RabbitMQ With Docker Compose rabbitmq.config文件在Run上被替换

时间:2017-09-08 08:37:18

标签: docker rabbitmq docker-compose dockerfile

我已经尝试了很多次,每次运行docker-compose up我的rabbitmq.config文件都会被替换。

以下是我的dockerfile。

FROM rabbitmq:3.6.11-managment
RUN rabbitmq-plugins enable rabbitmq_management
RUN rabbitmq-plugins list
COPY  ./config/rabbitmq.config ../../etc/rabbitmq/ 
COPY  ./config/test.json ../../etc/rabbitmq/ 

这是我的Docker-Compose文件。

version: '2'
services:
  rabbit:
    build:
      context: .
      dockerfile: rabbit.dockerfile
    container_name: rabbit
    hostname: lightrabbit    
    networks:
      - rabnet
    environment:
      - RABBITMQ_DEFAULT_USER=abcd
      - RABBITMQ_DEFAULT_PASS=pass    
    volumes:
      - ./config/rabbitmq:/etc/rabbitmq:rw
      - ./data:/var/lib/rabbitmq:rw
      - ./logs:/var/log/rabbitmq:rw
    ports:
      - 15672:15672  
      - 5672:5672
volumes:
  rabbitdata:
    driver: local
networks:
    rabnet:
        driver: bridge

我甚至在文件夹中添加了一个卷映射来测试它。 我在dockerfile中运行RUN rabbitmq-plugins enable rabbitmq_management的原因是因为默认情况下未启用管理插件。

1 个答案:

答案 0 :(得分:1)

将我的泊坞文件更改为此

FROM rabbitmq:3.6.11-management
COPY rabbitmq.config /etc/rabbitmq/
RUN chmod 777 /etc/rabbitmq/rabbitmq.config
WORKDIR /var/lib/rabbitmq/
RUN rabbitmq-plugins enable rabbitmq_management  --offline
RUN rabbitmq-plugins list

和我的撰写文件

version: '2'
services:
  rabbit:
    build:
      context: .
      dockerfile: rabbit.dockerfile
    container_name: rabbit
    hostname: lightrabbit    
    networks:
      - rabnet
    environment:
      - RABBITMQ_DEFAULT_USER=lighttrading
      - RABBITMQ_DEFAULT_PASS=P@ssw0rd_rabbit                 
    ports:
      - 15672:15672  
      - 5672:5672    

volumes:
  rabbitdata:
    driver: local
networks:
    rabnet:
        driver: bridge

其中一个棘手的部分是必须在我们的rabbitmq.config中定义此部分,否则运行命令rabbitmq-plugins enable rabbitmq_management将无效

{ rabbitmq_management, [
        { listener, [
            { port, 15672 },
            { ssl, false }
        ] },
        { load_definitions, "/etc/rabbitmq/definitions.json" }
    ] }