Docker Commands

In this article, let's discuss Docker Commands.

1. Finding the version 

One of the first things you want to know is how to find the installed docker version.

docker --version

2. Downloading the image

Let’s say you need to pull the docker image from dockerhub (docker repository). The following example of pulling the Apache HTTP server image.

docker pull httpd

3. Images

List all the docker images pulled on the system with image details such as TAG/IMAGE ID/SIZE etc.

docker images

4. Run

Run the docker image mentioned in the command. This command will create a docker container in which the Apache HTTP server will run.

docker run -it -d httpd

5. What’s running?

ps lists all the docker containers that are running with container details.

docker ps

6. ps -a

List all the docker containers running/exited/stopped with container details.

docker ps -a

7. exec

Access the docker container and run commands inside the container. I am accessing the Apache server container in this example.

docker exec -it 09ca6feb6efc bash

8. Removing the container

Remove the docker container with the container id mentioned in the command

docker rm 9b6343d3b5a0

9. Removing the image

Remove the docker image with the docker image id mentioned in the command

docker rmi fce289e99eb9

10. Restart Docker

Restart the docker container with the container id mentioned in the command.

docker restart 09ca6feb6efc

11. Stopping Docker

Stop a container with the container id mentioned in the command.

docker stop 09ca6feb6efc

12. Starting Docker

This command in docker starts the docker container with the container id mentioned in the command.

docker start 09ca6feb6efc

13. Kill

Stop the docker container immediately. The docker stop command stops the container gracefully; that’s the difference between a kill and a stop command.

docker kill 09ca6feb6efc

14. Commit

Save a new docker image with the container id mentioned in the command on the local system. In the example below, geekflare is the username, and httpd_image is the image name.

docker commit 09ca6feb6efc

15. Login

Login into the docker hub. You will be asked for your docker hub credentials to log in.

docker login

16. Push

Upload a docker image with the image name mentioned in the command on the dockerhub.

docker push geekflare/httpd_image

17. Docker network

The following command in docker lists the details of all the networks in the cluster.

docker network ls

18. Docker info

Get detailed information about docker installed on the system, including the kernel version, number of containers and images, etc.

docker info

19. Copying file

Copy a file from a docker container to the local system. In this example, I am copying httpd.pid file inside a docker container with id 09ca6feb6efc to /home/vyelve/

sudo docker cp 09ca6feb6efc

20. Checking history

Shows the history of a docker image with the image name mentioned in the command.

docker history httpd

21. Checking logs

Show the logs of the docker container with the contained id mentioned in the command.

docker logs 09ca6feb6efc

22. Searching image

Search for a docker image on dockerhub with the name mentioned in the command.

docker search hadoop

23. Updating configuration

Update container configurations. This shows all the update options.

docker update --help

24. Creating volume

Create a volume that the docker container will use to store data

docker volume create

25. Installing the plugin

Install a docker plugin vieux/sshfs with debug environment set to 1.

docker plugin install vieux/sshfs DEBUG=1

26. Logout

Logging out from dockerhub.

docker logout


Similar Articles