一.简介
Bind mounts and named volumes are the two main types of volumes that come with the Docker engine.
|
Named Volumes |
Bind Mounts |
Host Location |
Docker chooses |
You control |
Mount Example (using -v ) |
my-volume:/usr/local/data |
/path/to/data:/usr/local/data |
Populates new volume with container contents |
Yes |
No |
Supports Volume Drivers |
Yes |
No |
二.示例
1 2 3 4 5 6 7 8 9
| 创建镜像 docker build -t myupi . 挂载volume //容器内的文件夹不存在,docker会自动创建 docker run -d -p 12000:12000 --name upi -v /datatest/file:/filetest myupi
进入容器 docker exec -it 71d bash
|
/datatest/file和/filetest两个目录内的文件共享,其中一个改变另一个跟着改变(如果理解挂载的话,这句话就是废话)
三.docker -p
1
| -p 8080:80 Bind host’s port 8080 to container’s TCP port 80
|
参考:https://docs.docker.com/get-started/06_bind_mounts/