Docker allows you to package an application with all of its dependencies into a standardized unit for software development. More than that, Docker is a popular tool to make it easier to build, deploy and run applications using containers.
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
Sample image in which I installed python, I built it upon the official Ubuntu image.
docker pull [image name]
List all available docker images in your system
docker images [image name]
docker run -it [image name:tag] or [image id] bash[image name]
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
Here I installed python
apt-get install python
Save container to an image
docker commit [container id] [give image name:give new tag]
Create a docker hub account if you don’t have and login to that using terminal
docker login -u [username]
Create tag: Can be anything
docker tag [image name:tag] [docker hub username]/[image name:tag]
Push docker image to DockerHub
docker push [docker hub username]/[image name:tag]
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.