为RabbitMQ设置策略作为Dockerfile进程的一部分

时间:2016-02-13 18:26:55

标签: docker rabbitmq dockerfile

我尝试使用自定义策略集创建基于RabbitMQ存储库的Dockerfile。问题是我无法使用CMDENTRYPOINT,因为它会覆盖基本的Dockerfile,然后我必须提出自己的问题而且我不能使用RUNRUN我想走那条路。更不用说如果我不使用--offline,它将成为运行时命令的一部分,我希望它包含在图像中,而不仅仅是容器中。

我可以做的其他事情是使用rabbitmqctl命令,但问题是RabbitMQ服务器没有在构建时运行,并且RUN没有Error: unable to connect to node rabbit@e06f5a03fe1f: nodedown DIAGNOSTICS =========== attempted to contact: [rabbit@e06f5a03fe1f] rabbit@e06f5a03fe1f: * connected to epmd (port 4369) on e06f5a03fe1f * epmd reports: node 'rabbit' not running at all no other nodes on e06f5a03fe1f * suggestion: start the node current node details: - node name: 'rabbitmq-cli-136@e06f5a03fe1f' - home dir: /var/lib/rabbitmq - cookie hash: /Rw7u05NmU/ZMNV+F856Fg== 标志。 3}} CMD程序的命令。

当我使用docker' ENTRYPOINT命令设置策略时,这是我面临的错误:

updatesServer/
  App-0.1.win32.zip (client version running)
  App-0.2.win32.zip (this isn't fetched)
  App-0.2.win32.from-0.1.patch (this is fetched first)
  App-0.3.win32.zip (this is fetched third)
  App-0.3.win32.from-0.2.patch (this is fetched second)

那么我有没有办法为RabbitMQ设置策略而无需编写我自己的from esky import * from esky.util import appexe_from_executable def restart_this_app(): appexe = appexe_from_executable(sys.executable) os.execv(appexe,[appexe] + sys.argv[1:]) if hasattr(sys, "frozen"): app = esky.Esky(sys.executable, UPDATES_URL) print("You are running version "+app.active_version) print("Looking for updates...") if app.find_update() is None: print("No updates have been found.") else: print("Updates available. Updating...") try: app.auto_update() except Exception as e: print("Error while updating:", e) else: print("Update complete.") print("Restarting app...") time.sleep(3) restart_this_app() 和/或{{1}}版本?

2 个答案:

答案 0 :(得分:2)

RabbitMQ处于一个稍微棘手的情况,因为它的mnesia数据路径是基于容器的主机名。

s{<h(\d)>([^<]*)</h\g1>}{"=" x $1 . " $2 " . "=" x $1}gei;

对于其他图像构建,您可以为数据文件设定种子,或者编写root@bf97c82990aa:/# ls -1 /var/lib/rabbitmq/mnesia rabbit@bf97c82990aa rabbit@bf97c82990aa-plugins-expand rabbit@bf97c82990aa.pid 调用的脚本来启动应用程序或数据库并对其进行配置。使用RabbitMQ,容器主机名将在映像构建和运行时之间更改,因此不会拾取映像的配置。

我认为您在创建容器或启动时执行配置时会遇到困难。

选项

创建包装器RUN脚本以在启动后执行策略有点复杂,因为CMD在前台运行rabbit,这意味着您无法访问“启动后”点。 Docker并不真正执行后台进程,因此/usr/lib/rabbitmq/bin/rabbitmq-server没有多大帮助。

如果您使用Ansible,Chef或Puppet之类的东西来设置容器。为容器启动配置固定主机名。然后启动它并configure the policy作为下一步。这只需要完成一次,只要主机名是固定的并且您没有使用--rm flag

在运行时,systemd可以使用ExecStartPost完成对服务的配置。我相信大多数服务经理都会拥有相同的功能。我猜你最终可能会丢弃消息,或者至少在每次启动时都会出现错误,如果在配置完成之前有任何问题进入?

答案 1 :(得分:0)

您可以按照here所述配置策略。

Docker撰写:

  rabbitmq:
    image: rabbitmq:3.7.8-management
    container_name: rabbitmq
    volumes:
        - ~/rabbitmq/data:/var/lib/rabbitmq:rw
        - ./rabbitmq/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf
        - ./rabbitmq/definitions.json:/etc/rabbitmq/definitions.json
    ports:
      - "5672:5672"
      - "15672:15672"