在容器之间安装共享卷

时间:2018-01-18 10:29:35

标签: docker docker-volume

如何安装许多容器使用的卷?

这是我使用的命令:

docker run -d  -it  --name shared  --mount shared:/app ubuntu:latest

2 个答案:

答案 0 :(得分:0)

你正在使用错误的旗帜。用-v。替换--mount。

答案 1 :(得分:0)

您可以使用--mount,如下所示 -

创建容器1 -

$ docker run -d \
  -it \
  --name container1 \
  --mount source=vol1,target=/app \
  nginx:latest

创建容器2 -

$ docker run -d \
  -it \
  --name container2 \
  --mount source=vol1,target=/app \
  nginx:latest

现在,无论在/app内写入任何容器,都会使用source=vol1在所有容器中同步。

官方文件 -

  

最初,-v或--volume标志用于独立容器   并且--mount标志用于swarm服务。但是,开始   使用Docker 17.06,您也可以使用--mount with standalone   容器

因此,您可以将--mount用于独立容器以及Docker 17.06

相关问题