Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Introduction to Docker and practical application management application data

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

1. Three ways to mount data from the host to the container

Docker provides three ways to mount data from the host to the container: volumes:Docker manages part of the host file system (/ var/lib/docker/volumes). The best way to save data. Bind mounts: Mount files or directories anywhere on the host to the container. Tmpfs: mounts the file system that is stored in the memory of the host system and does not write to the host. If you do not want to persist data anywhere, you can use tmpfs while avoiding writing to the container writable layer to improve performance.

2.Volume

Create volume: docker volume create nginx-vol View Volume: docker volume lsdocker volume inspect nginx-vol Mount Volume: docker run-d-p 89:80-- name=nginx-test-- mount src=nginx-vol,dst=/usr/share/nginx/html nginx docker run-d-p 89:80-- name=nginx-test-v nginx-vol:/usr/share/nginx/html nginx Delete Volume: docker rm-f $(docker ps-a | awk'{print $1}') docker rm-f $(docker ps-qa) docker volume rm nginx-vol Note: 1. If no volume is specified, it is created automatically. two。 It is recommended to use-- mount, more general

3.Bind Mounts

Create a container with volumes: docker run-d-it-- name=nginx-test-- mount type=bind,src=/app/wwwroot,dst=/usr/share/nginx/html nginxdocker run-d-it-- name=nginx-test-v / app/wwwroot:/usr/share/nginx/html nginx verify binding: docker inspect nginx-test cleanup: docker stop nginx-testdocker rm nginx-test Note: 1. If the source file / directory does not exist, it will not be created automatically and an error will be thrown. two。 If the mount target is not an empty directory in the container, the existing contents of that directory will be hidden [root@localhost ~] # mkdir wwwroot Touch wwwroot/index.html [root@localhost ~] # docker run-d-p 89:80-- mount type=bind,src=$PWD/wwwroot,dst=/usr/share/nginx/html nginx9c675487b319d6a723f2de35abd09c465aca6472b91e7232a9de6893012f3f63 [root@localhost ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES9c675487b319 nginx "nginx-g 'daemon of …" 9 seconds ago Up 8 seconds 0.0.0.0 localhost 89-> 80/tcp sad_ Robinson [root @ localhost ~] # docker exec-it 9c675487b319 bashroot@9c675487b319:/# ls / usr/share/nginx/htmlindex.htmlroot@9c675487b319:/# cat / usr/share/nginx/html/index.html root@9c675487b319:/# exitexit [root@localhost ~] # cat wwwroot/index.html [root@localhost ~] # echo "hello" > wwwroot/index.html [root ~] # docker Exec-it 9c675487b319 cat / usr/share/nginx/html/index.htmlhello [root@localhost ~] # docker rm-f 9c675487b9c675487b [root@localhost ~] # cat wwwroot/index.html hello [root@localhost ~] #

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report