Common Docker commands
1. Help command
Docker version #docker info #docker info # Docker stats #Copy the code
2. Run the mirror command
docker images # view all mirrors; -a Lists all mirrors. -q Displays only the ID of the mirrorDocker Search Specifies the image name# query mirrorDocker pull Image name: version numberIf the version number is not specified, the latest version will be downloadedDocker RMI image ID# delete mirror
docker rmi -f $(docker images -aq) # Delete all mirrors
Copy the code
3. Container command
3.1 Starting a Container
Docker run [Optional] Image name#Parameters thatName - the name # container name - d # # background run - it USES interactive way, into the container to check the content, then add/bin/bash - p # designated container break - p IP: host port: container port; -p Host port: container port (most commonly used). -p container port -v host directory :docker container directory # mount data volume, two-way binding, no matter which of the two new files, the other side will synchronize # even if the container is not started, we change files in the host machine, #docker run -v /var/local/centos:/home centos # Named mount -v data volume name: directory in container :ro ro read-only rw read/write # Anonymous mount -v directory in container: directory in container :ro ro read-only rw read/write Docker volume ls docker volume inspect Docker volume name docker volume name --volume-from container name If the parent container is deleted, the data volume of the other container will not be deleted. If the parent container is deleted, the data volume of the other container will not be deleted.Copy the code
3.2 Viewing containers
Docker ps # view the current running container#Parameters that-a # Brings out the container that has been run in history; -q # Displays only the container ID. -aq # query all container ids; -n= number # Queries the most recent specified number of containersCopy the code
3.3 Exiting a Container
CTRL + P + Q # The container does not stop exitingCopy the code
3.4 Deleting a Container
Docker rm container id # docker rm container id # If forced to delete is docker rm -f docker rm -f $(docker ps - aq) # delete all containers docker ps - a - q | xargs docker rm # to delete all of the containerCopy the code
4. Use other commands
4.1 Background Start container
#Background startup containerDocker run -d specifies the image name#Problem: The container stops automatically when we start it
#When a Docker container runs in the background, it must have a foreground process
Copy the code
4.2 Viewing Logs
docker logs
#Write your own shell scriptdocker run -d centos /bin/sh -c "while true; do echo lybing; sleep 1; done"#Parameters that-tf # Display logs --tail Digital container ID # Number of logs to displayCopy the code
4.3 Viewing Process Information in a Container
Docker Top Container IDCopy the code
4.4 Viewing the Container Metadata
Docker inspect Container IDCopy the code
4.5 Entering the Running Container
#Our container usually runs in background mode, needing to go into the container and change some configuration
#After entering a new terminal, you can operate in itDocker exec -it container id bashshell #bashshell is the contents of the path where we view the container metadata#The second way is to enter the terminal where the container is executing and not start a new terminal. For example, our current container is printing a string, so we
#The terminal that comes in will be printing all the time, andexecWill not beDocker Attach Container IDCopy the code
4.5 Copying Files from containers to Hosts
#Go inside the container and create the fileDocker cp container id: docker cp container id: docker cpCopy the code