Home Linux Docker Commands with Examples

Docker Commands with Examples

What are docker basic commands?

As we have learned in the previous article about docker installation. Now we will learn how to use basic docker commands.

1. Find Docker Version

To find the installed docker version, run the following command.

$ docker --version
check docker version
Docker version

2. Download Docker Image

To download the docker image, run the below command.

$ docker pull <image_name>

3. List Downloaded Docker Images

To list the downloaded images on the system, run below command.

$ docker images

4. Launch Container

To launch a container, use the following command. For example, here we will run the Apache server within the container.

$ docker run -it -d httpd

5. List Running Containers

To list all the running containers, run the following command.

$ docker ps

We can use -a option to check all the stopped/shutdown containers.

$ docker ps -a

6. Remove Container

Run the following command to remove a container. For that, we need container id. We can get container id using docker ps command.

$ docker rm 8v5251d3b6b9

7. Restart Docker container

Run the following command to restart the docker container.

$ docker restart 83dag5sqn4ePw

Stop docker container:

$ docker stop 83dag5sqn4ePw

To start docker container:

$ docker start 83dag5sqn4ePw

8. Kill Docker container

We can use the following docker command to kill the container immediately.

$ docker kill 83dag5sqn4ePw

9. Docker Info

To get overview of installed services on docker, run the following command. It will tell us about how many containers running, stopped, images etc.

$ docker info

10. Copy File

To copy a file from a docker container to the local system, run the below command. In this example, we will copy the index.php file.

$ docker cp 83dag5sqn4ePw:/usr/local/apache2/index.php /home/arun/

where cp = copy command
83dag5sqn4ePw = container id

11. Search docker image

Run the following command to search docker images.

$ docker search ubuntu



That’s it. Hope you have learned the basic docker commands.

LEAVE A REPLY

Please enter your comment!
Please enter your name here