Just to do a good job
What is a Docker?
Docker is an open source application container engine, Docker can be very simple to keep online and offline services consistent. Prevent inconsistencies during development testing. Online user data recommended not to copy to the local yo (desensitization). At the same time, developer data can be packaged and sent to any environment for virtualization.
Docker advantage
- More efficient use of system resources, more lightweight than VM
- Faster startup time
- Consistent operating environment
- Continuous payment and deployment
- Easy migration, and convenient maintenance and expansion
Common Docker commands
Common Docker commands can be roughly divided into five categories: container life cycle management commands, container management commands, local image management commands, image warehouse management commands, Docker information viewing commands, and container rootfs commands. Next, the common commands of Docker are listed and used with examples
Container lifecycle management commands
1. Create Creates a containerCopy the code
$ docker create --name redis-new redis:v1
$ docker ps -a
Copy the code
2. Start /restart/stop Starts/restarts/stops the containerCopy the code
$ docker start cee694de0a764bc
$ docker ps
Copy the code
3. Run Creates and runs the containerCopy the code
$ docker run -itd -p 6379:6379 redis:v1
Copy the code
4. Exec access the Docker pseudo-terminalCopy the code
$docker exec -it ef5d1998b5c3 bash
#To exit, press Ctrl+D
Copy the code
5. Rm deleted the containerCopy the code
#Delete all containers
$docker rm $(docker ps -a -q)
Copy the code
Pause /unpause Pauses and starts processes in a containerCopy the code
$docker pause ef5d1998b5c3 # Stop providing external services
Copy the code
Container operation command
2. Inspect to check container details, Go TemplateCopy the code
$docker inspect -f {{".Metadata"}} redis
Copy the code
3. Top View the status of container processesCopy the code
$ docker top ef5d1998b5c3
UID PID PPID C STIME TTY TIME CMD
999 1096 1075 0 04:39 ? 00:00:02 redis-server *:6379
Copy the code
4. Port View the port mapping between the host and the containerCopy the code
$ docker port ef5d1998b5c36379 / TCP - > 0.0.0.0:6379Copy the code
5. Wait until it is closedCopy the code
$ docker wait ef5d1998b5c3
#The DOS interface is blocked until the container closes and resumes
Copy the code
Logs Displays internal logs or exception logs. 7. Event Displays container event logsCopy the code
Container warehouse operation
1. Pull an image from the remote warehouse to the local computer. 2Copy the code
Docker search -f stars=10 redis --no-trunc=falseCopy the code
3. Push the local image to the remote registry 4. Login login to the remote registry 5Copy the code
Local Mirroring operation
1. Images View the list of local mirrorsCopy the code
$ docker images -q # Display a list of mirror ids
Copy the code
2. Tags local mirrorCopy the code
$ docker tag redis:v1 redis:v2
Copy the code
Rmi delete the local image. 4. Build the image. Dockerfile 5. Save the image as a tar archive 6. Load the image (save command) 7. History Displays the creation history of the specified image 8Copy the code
Container rootfs command
1. Copy files between the cp container and the hostCopy the code
$ docker cp Desktop/Bookmarks 10132240d6ca:/data
Copy the code
Commit commit the modified image. 3. Diff View the changes of the image file systemCopy the code
Docker C/S details
Info View the details. 2. Version View the versionCopy the code
Network management
Network Port Mapping
# docker run -d -P --name redisdb redis
Copy the code
Note: Advanced network configurations do not need late padding.
Data volume
What is a data volume?
A data volume is a special directory for containers that bypasses the file system and provides many useful features:
- Data volumes are shared and reused between containers
- Changes to data volumes take effect immediately
- Data volume update does not affect the mirroring
- The volume exists until no container is used
Relevant command
Host folders are shared to the image
docker run -it -v /C/Users/lenovo/Desktop/editor.md-master:/webapp centos:latest
Copy the code
Data synchronization
#1. Create a data volume container dbData and mount the data volume to/dbData
docker run -it -v /dbdata --name dbdata centos:latest
#2. Run the volumes-from command in other containers to mount data volumes in the dbdata container
docker run -it --volumes-from dbdata --name db1 centos:latest
docker run -it --volumes-from dbdata --name db2 centos:latest
#Each of the three directories can be seen by the other containers if either side writes to the directory
Copy the code
Deleting a Data Volume
Docker stop 9589AD5ef688 docker rm -v db1 #Copy the code
Watch cross talk also want to knock code community notes
- Github
- CSDN
- The Denver nuggets
- Jane’s book
- Scan code to pay attention to me, never get lost