【问题标题】:How to restart rabbitmq inside docker如何在docker中重启rabbitmq
【发布时间】:2021-05-05 12:05:51
【问题描述】:

我正在使用rabbitmq docker镜像https://hub.docker.com/_/rabbitmq 我想在容器内的 rabbitmq.conf 文件中进行更改以测试配置,所以我尝试了

rabbitmqctl stop

进行更改后。但这会停止整个 docker 容器。 我什至尝试过

rabbitmq-server restart

但这也不能说明端口正在使用中。 如何在不重启整个容器的情况下重启服务?

【问题讨论】:

    标签: docker rabbitmq


    【解决方案1】:

    通常制作 Docker 容器是为了让它们在它们的主进程运行时存活。如果应用程序正常退出,容器也会正常退出。

    接受这种行为比反对它更容易,你只需要在你的主机上创建一个配置并将其挂载到容器中。之后,您可以更改本地文件并重新启动容器以使应用程序读取更新的配置。这样做:

    # Copy config from the container to your machine
    docker cp <insert container name>:/etc/rabbitmq/rabbitmq.config .
    
    # (optional) make changes to the copied rabbitmq.config
    ...
    
    # Start a new container with the config mounted inside (substitute /host/path
    # with a full path to your local config file)
    docker run -v /host/path/rabbitmq.config:/etc/rabbitmq/rabbitmq.config <insert image name here>
    
    # Now local config appears inside the container and so all changes 
    # are available immediately. You can restart the container to restart the application.
    

    如果您更喜欢硬方式,您可以自定义容器,以便它启动一个脚本(您必须编写它)而不是 rabbimq。该脚本必须在后台启动服务器并检查进程是否处于活动状态。您可以在“Run multiple services in a container”文章中找到如何执行此操作的提示。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 2012-05-30
      • 2016-12-04
      • 1970-01-01
      • 2022-11-09
      • 2020-04-07
      相关资源
      最近更新 更多