Source: Deep Learning on Medium
Docker containers for dummies
Docker allows you to package an application with all of its dependencies into a standardized unit for software development.
Why should you use Docker?
- Try any other version of OS in few seconds without uninstalling existing OS
- Save installation time on new machines: Install libraries, frameworks inside docker and use that image on any other machine
- Version compatibility: Since all libraries will be inside docker which is like a separate machine hence no version mismatching
How to use Docker?
Switch to “root” user or run all below command with “sudo” prefix as docker daemon needs “sudo” permission to run
apt-get install docker.io
Pull docker image from Docker Hub.
docker pull <image name>
List all available docker images in your system
Build a container out of docker image
Note: “Image Id” can be used instead of “image name:tag”
docker run -it <image name:tag> or <image id> bash
List all running containers:
List latest created running container
docker ps -l
List all containers which are created(Need not be running)
docker ps -a
Close a running container
docker stop <container id>
Restart a closed container
docker start <container id>
Go to the terminal of a running container
docker exec -it <container id> bash
Modify your container: Install libraries
Here I installed python
apt-get install python
Save container to an image
docker commit <container id> <give image name:give new tag>
Push the changes to docker hub
Create a docker hub account if you don’t have and login to that using terminal
docker login -u <username><Enter password>
Create tag: Can be anything
Tag will be a identifier for what this image is used for
docker tag <image name:tag> <docker hub username>/<image id:new_tag>
Push docker image to DockerHub
docker push <docker hub username>/<image id>
Finally, pull this image on any other machine and enjoy coding python without reinstalling python into it. Likewise, you can build Docker images on your machine and can reuse those images anywhere and get rid of the pain of reinstalling modules/ libraries every time.
Thanks! for reading. Please reach out to any queries.