Docker Profile
# What is: Similar redis of RDB and AOF, (more popular to say the equivalent of mobile hard disk) # can do 1 , container persistence 2, between the container inherit + persistence # how to use a direct command to add (-v) # Docker RUN -v host directory: image name directory container (docker run -it image name, this memory comparison) Example: RUN Expediting IT Docker -v / myVolume: / containVolume CentOS 1.1 provided read-only access to the container (the host can be modified container Read only) Docker RUN -v host directory: container directories: RO-only image name Read Docker RUN Expediting IT -v / myVolume: / containVolume: RO CentOS 2, was added DockerFile
Second, the use
1, the command added
[root @ linuxxx ~] # Docker RUN -it -v / myVolume: / containVolume CentOS # can automatically create a new directory # After you perform this sentence, has produced a binding relationship, you can use docker inspect ID Check Volumes or hostconfig respectively host vessel and into the respective end of file [@ linuxxx the root /] # CD myVolume / # native Linux end, host [@ linuxxx the root myVolume] # CAT b.txt a123qwer [@ f3c17a0046ed the root /] # CD containVolume / # container end [ @ f3c17a0046ed containVolume root] # vi b.txt # conclusion: either the host or create a file container or, modify the file or, can share resources ------------------ -------------------- # when the container exit, modified during which the host before reconnecting, is valid for container [root @ c23bbbea6835 /] # Exit Exit # to the host, [root @ linuxxx myVolume] # Touch c.txt [root @ linuxxx myVolume] # vi c.txt added 123 # # to the container, and re-visit the [root @ ~ linuxxx] # Docker get PS # -l ID, [root @ linuxxx ~] # [root @ linuxxx ~] # Docker Start run # f3c17a0046ed container f3c17a0046ed [root @ linuxxx ~] # Docker into the container the attach f3c17a0046ed # [root @ f3c17a0046ed /] # [root @ f3c17a0046ed /] # cd containVolume / # to enter the bindings file [@ f3c17a0046ed the root containVolume] # [@ f3c17a0046ed the root containVolume] # LL Total. 8 -rw-R & lt -. r-- the root. 1 the root. 9-Aug. 6 11:40 b.txt -rw-R & lt - r--. 1. Aug 6 11:50 4 root root c.txt [root @ f3c17a0046ed containVolume] # CAT c.txt 123 Conclusion: after the introduction of the container, still shared with the host resources
2, DockerFile add
# The above command add mode, supports only shared host and the container data # Because the host directory depend on the particular host, can not guarantee that all of the host there are specific directory usage: 1 , create mydocker folder in the root directory and into the 2 , can be added one or more data volumes to the mirror in the vOLUME command Dockerfile 3 , the image generating build, . 4 , the container RUN
[root @ linuxxx ~] # mkdir / mydocker # Create a folder [root @ linuxxx ~] # cd / mydocker / # to enter the folder [root @ linuxxx mydocker] # vi Dockerfile # write ---------- ----------------------------------------- # valume the Test # write the contents of the FROM CentOS VOLUME [ " / datavolume1 " , " / datavolume2 " , " / datavolume3 " ,] the CMD echo " Finished, sucess1 -------- " the CMD / bin / the bash ------------- ------------------------------------------ # Binding [@ linuxxx the root mydocker] # Docker Build -f / mydocker / Dockerfile pdun -t / CentOS. [@ Linuxxx the root mydocker] # Docker Images the REPOSITORY the TAG ID CREATED the IMAGE SIZE pdun / CentOS Latest 751b5f9475e5. 3 minutes ago Member 202MB [the root mydocker @linuxxx] # Docker RUN -it pdun / CentOS # can see if the successful creation of two containers [root @ 3c1a4034ed22 /] # LL drwxr-XR-the X-. 2 root root 6 Aug 6 14:02 datavolume1 drwxr -xr- X. 2. 6-Aug. 6 the root the root 14:02 datavolume2 #Into the container, create a file [root @ 3c1a4034ed22 /] # cd / datavolume1 [root @ 3c1a4034ed22 datavolume1] # pwd / datavolume1 [root @ 3c1a4034ed22 datavolume1] # Touch contioner01.txt -------------- -------------------------------------------------- -------- we did not create the host, come from let's open a new terminal [root @ linuxxx ~] # Docker PS CONTAINER PORTS the STATUS ID the IMAGE cREATED the COMMAND NAMES 3c1a4034ed22 pdun / CentOS " / bin / -c SH / bin / bash " 8 minutes ago Member Up 8 minutes angry_aryabhata c44b284600fd redis "docker-entrypoint.s…" 5 hours ago Up 5 hours 6379/tcp vibrant_spence [root@linuxxx ~]# [root@linuxxx ~]# docker inspect 3c1a4034ed22