如何使用rabbitmq docker撰写yml文件来构建docker镜像?

时间:2017-04-28 09:58:52

标签: docker rabbitmq install docker-compose

我是docker的新手,我知道如何提取Ubuntu Linux的图像并运行它。我只是想尝试一下rabbitmq,该网站说我们可以使用这样的docker-composer.yml文件:

rabbitmq:
  image: rabbitmq:management
  ports:
    - "5672:5672"
    - "15672:15672"

我用谷歌搜索了一段时间,但只找到YAML相关网站谈论如何编写复杂的YAML文件。但我的问题是,如何使用这个YAML文件与rabbitmq构建/组合任何docker镜像,以便我可以开始使用它?

2 个答案:

答案 0 :(得分:16)

在这里你可以找到一些例子:

https://github.com/Gsantomaggio/rabbitmqexample/tree/master/cluster_docker_compose

version: "2"
services:
  rabbit_node_1:
    environment:
      - RABBITMQ_ERLANG_COOKIE='secret_cookie'
    networks:
      - back
    hostname: rabbit_node_1
    image: "rabbitmq:3-management"
    ports:
      - "15672:15672"
      - "5672:5672"
    tty: true
    volumes:
      - rabbit1:/var/lib/rabbitmq
      - ./conf/:/etc/rabbitmq/
    command:  bash -c "sleep 10; rabbitmq-server;"
  rabbit_node_2:
    environment:
      - RABBITMQ_ERLANG_COOKIE='secret_cookie'
    networks:
      - back
    hostname: rabbit_node_2
    depends_on:
      - rabbit_node_1
    image: "rabbitmq:3-management"
    ports:
      - "15673:15672"
      - "5673:5672"
    tty: true
    volumes:
      - rabbit2:/var/lib/rabbitmq
      - ./conf/:/etc/rabbitmq/
    command:  bash -c "sleep 10; rabbitmq-server; "
volumes:
  rabbit1:
    driver: local
  rabbit2:
    driver: local

networks:
  back:

答案 1 :(得分:1)

这里是简单的 docker compose

version: "3"

services:

  rabbitmq:
    image: rabbitmq
    command: rabbitmq-server
    expose:
      - 5672
      - 15672