在容器之间挂载共享卷

Mount a shared volume between containers

如何挂载多个容器使用的卷?

这是我使用的命令:

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

您使用了错误的标志。将 --mount 替换为 -v.

您可以使用 --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 在所有容器中同步。

官方文档 -

Originally, the -v or --volume flag was used for standalone containers and the --mount flag was used for swarm services. However, starting with Docker 17.06, you can also use --mount with standalone containers.

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