Because the environment I tested was win10, There are some restrictions on the mounted directory ( for example : The test found that it could not be mounted D disc )

1,【 Container data volume 】

There can be a data sharing technology between containers !Docker Data generated in the container , Synchronize to local !
This is volume technology ! Directory mount , Put the directory in our container , Mount to Linux above ( or window above )!

【docker run -it -v /c/Users/gaoqiang/docker.sync.folder/:/home centos
/bin/bash】

stay window Medium test , You can only mount the disk to the user's directory , for example :docker@default:/c/Users/gaopinqiang$ Test if
-v /d/test Just mount to docker Directory in the host computer .window The local directory does not create this file .
We were in the container at this time /home Directory creation file ,window The directory on this machine will also synchronize

It can be done through 【docker inspect container id】 Check whether the mount is successful .
"Mounts": [ { "Type": "bind", "Source":
"/c/Users/gaopinqiang/docker.sync.folder", "Destination": "/home", "Mode": "",
"RW": true, "Propagation": "rprivate" } ],
Stop container , Modify files locally , The container is still synchronized after it is started .
[root@947bc6d88b40 home]# cat test.java modify by window [root@947bc6d88b40
home]#
benefit : We only need to modify it locally in the future , The container will synchronize automatically !

2,【 actual combat : install MySQL】
【docker run -e MYSQL_ROOT_PASSWORD=123456 -v
/c/Users/gwx284438/mysql/conf:/etc/mysql/conf.d -p 3307:3306 -d mysql:5.7】
Discovery will /var/lib/mysql Mount to our local will appear boot mysql Failure problem . Mount to docker The directory of will not . 【docker run -e
MYSQL_ROOT_PASSWORD=123456 -v /c/Users/gwx284438/mysql/conf:/etc/mysql/conf.d
-v /home/mysql/data:/var/lib/mysql -p 3307:3306 -d mysql:5.7】
This is the time mysql Will be synchronized to docker Of /home/mysql/data catalog
remarks : Even if it is deleted mysql container . We will create the same mount later data Catalogue , Table data is still available .
3,【 Name and anonymous mount 】
Anonymous mount :-v Path in container
docker run -d -P --name nginx01 -v /etc/nginx nginx # View all volume The situation ➜ ~
docker volume ls DRIVER VOLUME NAME local
33ae588fae6d34f511a769948f0d3d123c9d45c442ac7728cb85599c2657e50d local #
Found here , This is anonymous mount , We are here -v Only the path in the container is written , There is no path outside the write container !
Mount with name : adopt -v Volume name : Path in container
➜ ~ docker run -d -P --name nginx02 -v juming-nginx:/etc/nginx nginx ➜ ~
docker volume ls DRIVER VOLUME NAME local juming-nginx # adopt -v Volume name : Path in container #
Take a look at this volume 【docker volume inspect juming_nginx】 $ docker volume inspect
juming_nginx [ { "CreatedAt": "2020-09-27T06:24:10Z", "Driver": "local",
"Labels": null, "Mountpoint":
"/mnt/sda1/var/lib/docker/volumes/juming_nginx/_data", "Name": "juming_nginx",
"Options": null, "Scope": "local" } ]
be-all docker Volume in container , If there is no specified directory, the /var/lib/docker/volumes/xxxx/_data lower .

If a directory is specified ,docker volume ls You can't see it ( For example, we wrote earlier -v /home/nginx:/etc/nginx nginx)

Three kinds of mounting : Anonymous mount , Mount with name , Specified path mount
-v Path in container # Anonymous mount -v Volume name : Path in container # Mount with name -v / Host path : Path in container # Specified path mount docker volume ls
You can't see it , Slanted bar started
4,【 Data volume container 】–volumes-from
One container uses the data volume of another container directly , You can make more than one MySQL Synchronize data !

for example :
Start the first one mysql container , port 3307 【docker run -e MYSQL_ROOT_PASSWORD=123456 --name mysql01
-v /home/mysql/conf:/etc/mysql/conf.d -v /home/mysql/data:/var/lib/mysql -p
3307:3306 -d mysql:5.7】 add --volumes-from Parameter starts the second mysql , port 3308 【docker run -e
MYSQL_ROOT_PASSWORD=123456 --name mysql02 -p 3308:3306 --volumes-from mysql01
-d mysql:5.7】 window It can be started normally during the test 2 individual mysql, But the second one mysql use HeidiSQL The tool cannot be connected .
conclusion :
Transfer of configuration information between containers , The lifecycle of data volume containers lasts until no containers are used .
But once you make it local , This is the time , Local data will not be deleted !

5,【DockerFile introduce 】
dockerfile Is used to build docker Mirrored files ! Command parameter script !
Build steps :
1, Write one dockerfile file 2, docker build Building is called a mirror image 3, docker run Run image 4, docker
push Publish image (DockerHub , Alicloud warehouse )
DockerFile Construction process :
1, Each reserved keyword ( instructions ) They all have to be capital letters 2, Execution order from top to bottom 3,# Represents a comment 4, Each instruction creates and submits a new image , And submit !

【DockerFile Instructions 】
FROM # base image , It all starts here MAINTAINER # Who wrote the image , full name + mailbox RUN # Commands to be run during image construction ADD #
step ,tomcat image , this tomcat Compressed package ! Add content Add same directory WORKDIR # The working directory of the mirror VOLUME # Mounted directory EXPOSE #
Reserved port configuration CMD # Specifies the command to run when this container starts , Only the last one will take effect , Can be replaced . ENTRYPOINT #
Specifies the command to run when this container starts , You can append commands ONBUILD # When building an inherited DockerFile It will run at this time ONBUILD Instructions for , Trigger instruction .
COPY # similar ADD, Copy our files into the image ENV # Set environment variables when building !
【Dockerfile Practical test 】 Create your own centos
# 1, to write Dockerfile file FROM centos MAINTAINER gaoqiang<gaoqiang@huawei.com> ENV
MYPATH /usr/local WORKDIR $MYPATH EXPOSE 80 CMD echo $MYPATH CMD echo
"---end---" CMD /bin/bash # 2, Build the image from this file ( Pay special attention to the one at the back .) # command docker build -f File path
-t Image name :[tag] . 【docker build -f mydockerfile-centos -t qiang_centos:1.0 .】
Success will have the following print : Successfully built c1cdfa249f94 Successfully tagged qiang_centos:1.0
# 3, test run . Start our centos, You can see WORKDIR $MYPATH This works . $ docker run -it
qiang_centos:1.0 [root@8c156c8536e5 local]# pwd /usr/local [root@8c156c8536e5
local]# adopt 【docker history id】 You can view the history of the build $ docker history qiang_centos:1.0 IMAGE
CREATED CREATED BY SIZE COMMENT c1cdfa249f94 6 minutes ago /bin/sh -c #(nop)
CMD ["/bin/sh" "-c" "/bin 0B 02641c0cd60b 6 minutes ago /bin/sh -c #(nop) CMD
["/bin/sh" "-c" "echo 0B 13820e2c4c5f 6 minutes ago /bin/sh -c #(nop) CMD
["/bin/sh" "-c" "echo 0B ac4421f35831 6 minutes ago /bin/sh -c #(nop) EXPOSE 80
0B 7720b56e0b43 6 minutes ago /bin/sh -c #(nop) WORKDIR /usr/local 0B
12c15d13d87f 6 minutes ago /bin/sh -c #(nop) ENV MYPATH=/usr/local 0B
082e5849d94b 6 minutes ago /bin/sh -c #(nop) MAINTAINER gaoqiang<gaoqi 0B
0d120b6ccaa8 6 weeks ago /bin/sh -c #(nop) CMD ["/bin/bash"] 0B <missing> 6
weeks ago /bin/sh -c #(nop) LABEL org.label-schema.sc 0B <missing> 6 weeks ago
/bin/sh -c #(nop) ADD file:538afc0c5c964ce0d 215MB
6,【Dockerfile Medium CMD and ENTRYPOINT difference 】
CMD # Specifies the command to run when this container starts , Only the last one will take effect , Can be replaced . ENTRYPOINT # Specifies the command to run when this container starts , You can append commands
test CMD:
# to write dockerfile file $ vim dockerfile-test-cmd FROM centos CMD ["ls","-a"] # Building a mirror image
$ docker build -f dockerfile-test-cmd -t cmd-test:0.1 . # Run image $ docker run
cmd-test:0.1 . .dockerenv bin dev # Want to add a command -l become ls -al $ docker run
cmd-test:0.1 -l docker: Error response from daemon: OCI runtime create failed:
container_linux.go:349: starting container process caused "exec: \"-l\":
executable file not found in $PATH": unknown. ERRO[0000] error waiting for
container: context canceled # cmd In the case of -l Replaced CMD["ls","-l"]. -l It's not an order, so it's wrong .
test ENTRYPOINT:
# to write dockerfile file $ vim dockerfile-test-entrypoint FROM centos ENTRYPOINT
["ls","-a"] # Our orders , It's a direct splice in our ENTRYPOINT After the command $ docker run entrypoint-test:0.1
-l total 56 drwxr-xr-x 1 root root 4096 May 16 06:32 . drwxr-xr-x 1 root root
4096 May 16 06:32 .. -rwxr-xr-x 1 root root 0 May 16 06:32 .dockerenv
lrwxrwxrwx 1 root root 7 May 11 2019 bin -> usr/bin drwxr-xr-x 5 root root 340
May 16 06:32 dev drwxr-xr-x 1 root root 4096 May 16 06:32 etc drwxr-xr-x 2 root
root 4096 May 11 2019 home lrwxrwxrwx 1 root root 7 May 11 2019 lib -> usr/lib
lrwxrwxrwx 1 root root 9 May 11 2019 lib64 -> usr/lib64 ....
Summary : Clear schematic diagram :

Technology
©2019-2020 Toolsou All rights reserved,
data structure C Parking management of language 300 million people are working hard Java Share five face to face experience ,offer Taken ! Byte three side remote ,Java+Redis+ network + database + algorithm , Easy to kill interviewers ?C/C++ The 11th Blue Bridge Cup provincial competition B Group 2 Junior college background Java Post , Who says that there is no spring for college programmers ? new iPhone I won't support it 5G Will lead to further decline in shipment Not yet Spring? Ali P8 Summative 100 Analysis of Dao interview , Let you hammer the interviewer Upright code analysis __ Principle of two wheel balance car 【C language 】 Mine clearance game details Some suggestions for novice programmers to write practical business code in confusion