Common Docker commands
1. View all mirrors
Docker image ls abbreviation: docker images
two。 View all running containers
Docker container ls abbreviation: docker ps
3. View all containers
Docker container ls-an abbreviation: docker ps-a
4. Delete Container
Docker rm container container ID abbreviation: docker rm container ID
5. Delete Mirror
Docker image rm image ID abbreviation: docker rmi image ID
6. If there are many containers to be deleted, list all the container ID
Docker container ls-a | awk {'print$1'} / / output the first column abbreviated: docker container ls-aq delete all containers: docker rm $(docker container ls-aq)
7. Delete all exited containers
Docker container ls-f "status=exited" / / list all exit containers abbreviated: docker ps-f "status=exited" docker container ls-f "status=exited"-Q / / list all exit containers ID abbreviation: docker ps-f "status=exited"-qdocker rm $(docker container ls-f "status=exited"-Q) abbreviation: docker rm $(docker ps-f "status=exited"-Q)
8. Create a container by mirroring
Docker run-- name-d-p 8080 ID explains:-- name gives the container an alias-d for background operation-p container port and host port mapping
9. Create an image by the container (because the container may change during use, for example: a centos container with the vim plug-in installed)
Docker container commit abbreviation: docker commit Note: this is not recommended
10. Create a mirror through Dockerfile
Docker image build abbreviation: docker build
11. Enter a container that is running
Docker exec-it container name / bin/bash (or / bin/sh)
twelve。 Copy the files in the container to the host
# docker cp container name: the path of the file to be copied in the container should be copied to the corresponding path of the host docker cp nginx:/usr/share/nginx/nginx.tar / usr/local
13. Copy the files from the host to the container
# File path to be copied by docker cp Container name: to copy to the corresponding path docker cp / usr/local/nginx.tar nginx:/usr/share in the container