Command#
docker images
List all images
docker run -it image
Run and maintain a specific image
docker ps -a
List all containers (including those not running)
docker container prune
Delete all stopped containers
docker rm container
Delete a specified container
docker port container
View the ports mapped by a container
docker start container
Start a specified container
docker stop container
Stop a specified container
docker search image
Search for the desired image
Dockerfile#
Trick#
docker run --rm image
Automatically pull and run the image if it does not exist, and automatically delete the container after the image finishes running
docker run -d -P --name specify a name image
The terminal interface can be freely closed without affecting the continuous operation of the container, mapping the container's ports to random ports on the host machine, and specifying a name for the container
docker run -p host port:image port image
Map the image's port to a port on the host machine to start the container