Docker installation
The installation can be viewed directly on the official website.
Official website installation reference manual: https://docs.docker.com/engine/install/centos/
Docker start
systemctl start docker
View Docker version:
docker version
To view the installed image:
docker images
Test run hello
docker run hello-world
Uninstall Docker
systemctl stop docker yum -y remove docker-ce docker-ce-cli containerd.io rm -rf /var/lib/docker
Docker help command
docker version # Display Docker version information. docker info # Displays Docker system information, including the number of images and containers. docker --help # help
Docker common commands
docker search Image name //Search image Optional: docker search mysql --filter=stars=1000 Filter out images with more than 1000 likes
Download Image
docker pull Image name //If the version number is not written, the default version is the latest version
delete mirror
docker rmi -f Image name or image Id
Start of window
[the external chain image transfer fails. The source station may have an anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-7FleC7nt-1646553270045)(E:\sysy\Pictures \ BiliBili animation \ image-20220306152414845.png)]
docker run -it centos /bin/bash
Exit window: exit
Put the container in the background without closing and use ctrl+p+q;
Container view
docker ps //Lists the containers currently in use docker ps -a //List all containers
Start stop container
docker start Container name or container id Start container docker restart ... Restart container docker stop ... Stop container docker kill ... Force stop container
Delete container
docker rm container id Delete specified container docker rm -f $(docker ps -a -q) Delete all containers docker ps -a -q |xargs docker rm Delete all containers
Start the container in the background mode: docker run -d centos
Cleaning stopped containers
docker container prune
View container log
docker logs -f -t --tial container id docker logs container id
View the process information of the running container
docker top container Id
View metadata of container / image
docker inspect container id
Enter the running container
Command 1:
docker exec -it container id bashShell docker attach container id difference: exec Is to open a new terminal in the container and start a new process attach The terminal that directly enters the container startup command will not start a new process
Copy files from container to host
docker cp container id:In container path destination host path eg: docker cp 7f9ead6f906b:/home/f1 /home
Docker visualization
Portal is a graphical management tool of Docker. It provides functions such as status display panel, rapid deployment of application templates, container mirroring, basic operations of network data volumes (including uploading and downloading images, creating containers, etc.), event log display, container console operation, centralized management and operation of Swarm clusters and services, login user management and control, etc. The function is very comprehensive, which can basically meet all the needs of small and medium-sized units for container management.
docker submit image
docker commit creates a new image from the container.
docker commit -m="Description information submitted" -a="author" container id Name of target image to be created: [tag name]
Docker data volume
When using the docker run command, use the - v flag to create a data volume and mount it into the container.
docker run -it -v Host absolute path directory:Directory image name in container
After the mount is successful, the files created in the container will also be seen in the host computer.
DockerFile
DockerFile is a build file used to build Docker images. It is a script composed of a series of commands and parameters.
- Create a DockerFile
- build generate image
build generates an image and obtains a new image test CentOS. Note that there is one at the end
docker build -f /home/docker-test-volume/dockerfile1 -t test-centos .
That must not be forgotten
The container can then be started:
docker run -it test-centos /bin/bash
Anonymous mount and named mount
-v path in container
docker run -d -P --name nginx01 -v /etc/nginx nginx
You can view the mounted list with the command docker volume ls
These unspecified names are all anonymous mounts. We -v only write the path inside the container, not the path outside the container
[root@VM-0-6-centos ~]# docker volume ls DRIVER VOLUME NAME local 4d0221bc0d8b9e44fb2e878cd3efcacb9b4bd51c8e135d79c549f7a6345f3a24 local 7a1e6924fed1cc5ea6a386d9b2542c0ffc53fada1755bc7d09601274dff6ddd0 local 7adb0e2e33503b17abfd453fded4b0cd9d9e8b05e064d248dc47de0da6456788 local adaa3053cb2ff95afc7bab51451f4b1167aa1b9056398ed44b0d4cae9580db52
The mount directory is: / var / lib / docker / volumes / volume name/_ data
The disadvantage of anonymous mounting is that it is difficult to maintain, and it is unclear which container the directory is mounted on
Named mount
-v volume name: / path in container
[root@VM-0-6-centos ~]# docker run -d -P --name nginx02 -v juming:/etc/nginx nginx 112f36599f077eada56197c22dd3b3a3eaba2e5bb38bf2cb19adc783163991e7 [root@VM-0-6-centos ~]# docker volume ls DRIVER VOLUME NAME local 4d0221bc0d8b9e44fb2e878cd3efcacb9b4bd51c8e135d79c549f7a6345f3a24 local 7a1e6924fed1cc5ea6a386d9b2542c0ffc53fada1755bc7d09601274dff6ddd0 local 7adb0e2e33503b17abfd453fded4b0cd9d9e8b05e064d248dc47de0da6456788 local adaa3053cb2ff95afc7bab51451f4b1167aa1b9056398ed44b0d4cae9580db52 local juming
View the mounted Directory: docker volume VOLUME-NAME
In the mount operation, if the directory name is not specified, it is under / var/lib/docker/volumes / directory by default
[the external chain picture transfer fails, and the source station may have anti-theft chain mechanism. It is recommended to save the picture and upload it directly (img-3lI52oSr-1646553270047)(E:\sysy\Pictures \ BiliBili animation \ image-20220306154859645.png)]
Difference between CMD and ENTRYPOINT
As we said before, both commands specify the commands to be run when a container starts
-
CMD
There can be multiple CMD instructions in Dockerfile, but only the last one takes effect. CMD will be replaced by the parameters after docker run!
-
ENTRYPOINT
The parameters after docker run will be passed to ENTRYPOINT as parameters, and then a new command combination will be formed!
lower
[external chain picture transferring... (img-3lI52oSr-1646553270047)]
Difference between CMD and ENTRYPOINT
As we said before, both commands specify the commands to be run when a container starts
-
CMD
There can be multiple CMD instructions in Dockerfile, but only the last one takes effect. CMD will be replaced by the parameters after docker run!
-
ENTRYPOINT
The parameters after docker run will be passed to ENTRYPOINT as parameters, and then a new command combination will be formed!