多个 docker 服务器使用相同的容器
Multiple docker servers using same containers
我有多个虚拟机,它们都是 运行 Docker,我需要它们都能够 start/stop 同一个容器。例如,如果我在一个 VM 的一个容器中有一个文本文档,我将需要能够在任何 Docker 服务器上启动和编辑该文本文档(因此它们都是互连的)。我在想我可以把容器放在一个共享实例上,但后来我不确定如何让每个 Docker 服务器从那里启动它们。有什么想法吗?
如果您希望在 Docker 个容器之间共享数据,我将从数据卷或数据卷容器开始:
Data volumes
A data volume is a specially-designated directory within one or more
containers that bypasses the Union File System to provide several
useful features for persistent or shared data:
- Volumes are initialized when a container is created
- Data volumes can be shared and reused between containers
- Changes to a data volume are made directly
- Changes to a data volume will not be included when you update an image
- Volumes persist until no containers use them
Creating and mounting a Data Volume Container
If you have some persistent data that you want to share between
containers, or want to use from non-persistent containers, it's best
to create a named Data Volume Container, and then to mount the data
from it.
https://docs.docker.com/userguide/dockervolumes/
您使用 docker run
命令的 -v
选项指定了一个数据卷。然后,您可以使用 --volumes-from
将卷从 docker 卷容器安装到您想要与之共享数据的任何其他容器。以上示例的完整详细信息 link.
我有多个虚拟机,它们都是 运行 Docker,我需要它们都能够 start/stop 同一个容器。例如,如果我在一个 VM 的一个容器中有一个文本文档,我将需要能够在任何 Docker 服务器上启动和编辑该文本文档(因此它们都是互连的)。我在想我可以把容器放在一个共享实例上,但后来我不确定如何让每个 Docker 服务器从那里启动它们。有什么想法吗?
如果您希望在 Docker 个容器之间共享数据,我将从数据卷或数据卷容器开始:
Data volumes
A data volume is a specially-designated directory within one or more containers that bypasses the Union File System to provide several useful features for persistent or shared data:
- Volumes are initialized when a container is created
- Data volumes can be shared and reused between containers
- Changes to a data volume are made directly
- Changes to a data volume will not be included when you update an image
- Volumes persist until no containers use them
Creating and mounting a Data Volume Container
If you have some persistent data that you want to share between containers, or want to use from non-persistent containers, it's best to create a named Data Volume Container, and then to mount the data from it.
https://docs.docker.com/userguide/dockervolumes/
您使用 docker run
命令的 -v
选项指定了一个数据卷。然后,您可以使用 --volumes-from
将卷从 docker 卷容器安装到您想要与之共享数据的任何其他容器。以上示例的完整详细信息 link.