Get the App
SLTechnology News&Howtos  ›  Servers  › 

Introduction to Docker and practical application management application data

Shulou Source: shulou.com Published: 2022-06-03 00:48:51 10月18日 Update

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 ~] #

Tags: Containers data hosts hosts files methods directories systems hosts locations storage applications management memory content and at the same time recommendations performance source files targets Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL NVidia vpn Xiaomi OPPO Reno