opened image

    The trend of Docker containers is growing exponentially as it minimizes the cost of deploying projects, so a good knowledge of Docker commands will give you the necessary start to understand Docker at a basic level and how to manage it.

    In this article, we will look at some commands for managing Docker containers. We will see how to create them, run them, stop them, restart them, read logs, etc.

    So let's get started:

    1. Docker version

    docker --version


    This command is used to get the currently installed version of Docker.

    2. docker-pull

    This command is used to download images from the Docker repository -





    docker pull ubuntu


    3. Run the Docker container (docker run -it -d <image name>)





    docker run -it -d ubuntu


    4. Displaying a list of running containers





    docker ps


    5. To see not only running containers, but also stopped ones, use the following command:





    docker ps -a


    As you can see from the screenshot below, in the list of all containers, the hello-world container was stopped 7 weeks ago.

    6. To stop the container, use the command:





    docker stop


    For example, let's stop a running ubuntu container. To do this, we find out the container id with the docker ps command:

    And let's stop it:





    docker stop 2ef4b22c73f1


    7. To access the running container, use the docker exec command. For example, let's connect to the ubuntu container and start the bash shell.





    docker exec -it ef4b22c73f1 bash


    With the hostname command, we saw that we are in a container with the id of the ubuntu container.

    8. The inspect command - allows you to see detailed information from the running Docker container. For example, to see all the information about the phpmyadmin container, use the following command:





    docker inspect phpmyadmin


    In the snippet below, we can see some of the settings, options, and mount paths on the host machine of this container.

    9. The docker kill command can be used to kill a container. It immediately stops it, which stops it from running. This is useful when you need to quickly complete its work. Since when using the docker stop command, the container has the ability to stop correctly.

    To execute this command, you need to know the id of the container.





    docker kill df5d97c41eb4


    10. To create your own Docker image, there is a docker commit command. This command creates a new editable container image on the local system. After that, it can be uploaded to docker hub and used in other projects.

    docker commit <container id> <username/imagename>

    11. If we need to find out what images we have installed, we will use the docker images command.





    docker images


    12. To remove a stopped container, there is a docker rm command. For example, let's remove the ubuntu container that we created in this article:





    docker rm 2ef4b22c73f1


    13. The docker rmi command is used to remove an image from local storage. This command can be used especially when you need to free up space on the server.

    In this article, we have covered all several commands, but they are very important for basic administration of docker containers. In the next article, we will look at a list of important commands for working with docker-compose