It is a software platform that was released on 20 March 2013. This platform allows you to create container processes, which are simply processes that have all the required dependencies packaged in itself. It doesn’t use the host system’s packages to run.
This allows one to run things in isolation and minimise dependency issues and package conflicts that occur when you develop software. Docker runs all these processes run on the linux kernel as root. It is present on other operating systems as well, but it is best suited for the linux kernel, in my opinion.
This concept isn’t new however, so what makes docker different, in my opinion is
For more information, I suggest you look into other blogs or youtube videos to get a better understanding.
docker run <image name>
This is a simple way of running an image to create a container. It will do something only if the docker image that you are pulling is made to do something when run like this (usually not the case)
A more useful way of doing this would be something like
docker run -it -v $(PWD):/my_folder_in_container -w /my_folder_in_container --rm --name <customname> <image name>
This is a long command, let’s break it down and understand the arguments. More of them can be found here if you want a better explanation or other use cases.
-it
ensures that you run in interactive mode, opening a bash shell for you to play around inside the container.-v
will allow the directory current host’s working directory $PWD
to be mounted onto the folder /my_folder_in_container
, as given by the example above.
$(PWD)
is so that if there is any space in the working directory, it doesn’t cause any issues.-w
Will create a directory named /my_folder_in_container
inside the root directory of the container.--rm
Will delete the container once the container is exited (either manually from the bash terminal or if the command that was to be executed on startup is done running)--name
will allow you to put your own name <customname>
instead of making docker do that for you automatically, for the image <image name>
that you are making the container of.docker start <customname>
This starts a docker container with the name <customname>
.
docker exec -it <customname> bash
docker exec <customname> python /mycode.py
and it will execute the python script mycode.py
if it is present inside the container’s root directory. This is not in interactive mode, so upon execution, the container will be exited.docker kill <customname>
This kills a running container of the name <customname>
docker pull <image name>
This command pulls the docker image <image name>
docker ps
This shows all running containers
docker ps -a
docker login
Lets you login to your dockerhub account from where you can push, pull containers and images in your account, among other things.
docker commit <customname> <new_image_name>:latest
Once you have logged in, this command allows you to commit all changes to the container <customname>
and save it to an image named <new_image_name>
with a tag latest
, to the user smellingsalt
.
docker push smellingsalt/<new_image_name>:latest
This will push the docker image smellingsalt/<new_image_name>
to the dockerhub account smellingsalt
with a tag latest
After installing Docker, to prevent having to always type sudo
before every command, run the following to add the current user in a created user group.
sudo usermod -aG docker $USER
# apply changes to current shell (or logout/reboot)
$ newgrp docker
Will be updated soon!