Docker command

Docker command1. View detailed information2. View the version number3. Pull the image4. Run the image4.1. View the running image4.2. View the running or stopped image5. Clean up images6. View local images7. Delete images8. Submit the image9. Stop the image10. Multiple terminals enter the same container

Docker engine includes Docker CLI, which provides command line tools for interacting with Docker daemon. This tutorial introduces the usage of common Docker commands.

1. View detailed information

docker info

image-20250105134326862

2. View the version number

docker --version

image-20250105134400721

3. Pull the image

docker pull <image_name>

If no tag is specified, the image with the latest tag will be pulled by default.

docker pull <image_name>:

image-20250105141705494

4. Run the image

If there is no image to be run locally, docker will automatically pull the corresponding image.

docker run <image_name>

docker pull <image_name>:

Start the specified container and exit:

Start the specified container in interactive mode: Enter exit to exit

image-20250105142432302

4.1. View the running image

docker ps

4.2. View the running or stopped image

image-20250105142517865

5. Clean up images

docker container prune

image-20250105142635954

6. View local images

docker images

image-20250105142659185

7. Delete images

Note: The image to be deleted needs to be stopped and cleaned up

docker rmi <image_name>

docker rmi <image_name>:

image-20250105143042342

8. Submit the image

Pull and run the ubuntu:18.04 image in interactive mode

docker commit <image_name>:

Note: Modify according to the actual CONTAINER ID

image-20250105144610398

9. Stop the image

If you run the container in interactive mode and the terminal enters the container, you can enter exit in the container to stop the container;

If you close the container externally, you can use the docker stop command.

docker stop

Note: Modify according to the actual CONTAINER ID

image-20250105144810720

10. Multiple terminals enter the same container

Containers are isolated from each other. Directly using the command to run the image will start different containers; if you need to perform operations in the same container, you need to use the command to enter the same container.

Run the ubuntu:18.04 image in interactive mode:

View the running container:

docker exec

Enter the running container in interactive mode: modify according to the actual CONTAINER ID

image-20250105160213704