在Rancher中扩展具有不同但持久卷的Docker容器 [英] Scaling Docker containers in Rancher with different but persistent volumes

查看:272
本文介绍了在Rancher中扩展具有不同但持久卷的Docker容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试用Rancher扩展容器(但也可以使用Docker Compose,因为这更多是一个抽象的问题),同时在持久但独特的卷之间架起桥梁。

I'm currently trying to bridge the gap between persistent, but unique volumes while scaling containers with Rancher (alternatively Docker Compose, since this is more of an abstract question).

以Minecraft服务器为例,我在Rancher / Compose中定义了一个服务,该服务使用命名卷作为其data / world目录(例如-v minecraft_data:/ data,Minecraft映像从该目录中加载其世界文件/数据目录)。我使用这样的命名卷的原因是,我希望它在服务升级之间保持不变(例如,我要更改映像版本,或者想要更改某些环境变量),而匿名卷是不可能的。

Take as an example a Minecraft server, I have a Service defined in Rancher/Compose which uses a named volume as its data/world directory (e.g. -v minecraft_data:/data where the Minecraft image loads its world files from this /data directory). The reason I'm using such a named volume, is that I want it to persist between service upgrades (e.g. I'm changing the image version, or want to change some environment variables), which would not be possible with an anonymous volume.

现在,当尝试扩展我的服务时,我要么让多个容器访问同一数据(不适用于许多用例),要么在以下情况下失去服务的可升级性:使用匿名卷。

Now when trying to scale up my service, I'm either getting multiple containers accessing the same data (not good for many use cases), or losing the service upgradeability when using anonymous volumes.

是否有任何工具,最佳实践或模式可以帮助解决此问题?

Are there any tools, best practices or patterns that might help with this issue?

推荐答案

在当前版本的rancher(当前为v1.4)中存储驱动程序。这样,您就可以创建在环境,堆栈或容器范围内的卷。

In current versions of rancher (v1.4 at this time) storage drivers can be plugged in at the environment infrastructure level. This allows you to create volumes that are scoped at the environment, stack, or container.

对于您的用例,听起来每个容器的范围就是您所需要的。使用 rancher-compose ,您可以执行以下操作:

For your use case, it sounds like per-container scope is what you need. Using rancher-compose you do something like:

version: '2'
services:
  foo:
    image: busybox
    volumes:
    - bar:/var/lib/storage
    command: /bin/sh -c 'while true; do sleep 500; done'
volumes:
  bar:
    per_container: true

然后, rancher-compose up -d 将使用一个容器和唯一的卷创建堆栈和服务。 rancher scale foo = 2 将创建另一个具有其自身卷的容器,依此类推。您还可以为每个卷指定卷存储驱动程序,例如 rancher-ebs rancher-nfs 及其各自的选项。

Then, rancher-compose up -d will create the stack and service with one container and a unique volume. rancher scale foo=2 will create another container with its own volume, etc. You can also specify volume storage drivers for each volume like rancher-ebs or rancher-nfs with their respective options.

这篇关于在Rancher中扩展具有不同但持久卷的Docker容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆