简体   繁体   中英

How to docker-compose ThingsBoard + RabbitMQ?

Following the tutorial via ThingsBoard , it seems that they suggest to use the local desktop installation for the RabbitMQ and just run the docker-compose with some variables that reference it.

I personally do not like installing such apps directly on my PC, and prefer a docker instance of them.

I wish to try and sync both my docker ThingsBoard and RabbitMQ via Docker.

This is the docker-compose.yml file i am currently using:

version: '2.2'
services:
  mytb:
    privileged: true
    restart: always
    depends_on: 
      - rabbitmq
    image: "thingsboard/tb-postgres"
    ports:
      - "9091:9090"
      - "1883:1883"
      - "7070:7070"
      - "5683-5688:5683-5688/udp"
    environment:
      TB_QUEUE_TYPE: rabbitmq
      TB_QUEUE_RABBIT_MQ_USERNAME: test
      TB_QUEUE_RABBIT_MQ_PASSWORD: test123369
      TB_QUEUE_RABBIT_MQ_HOST: localhost
      TB_QUEUE_RABBIT_MQ_PORT: 5672
    volumes:
      - ./mytb-data:/data
      - ./mytb-logs:/var/log/thingsboard

  rabbitmq:
    image: rabbitmq:3-management
    environment:
      # RABBITMQ_ERLANG_COOKIE: 'asdfjasifasjfawfjisfjasifjioasjfoiasj'
      RABBITMQ_DEFAULT_USER: test
      RABBITMQ_DEFAULT_PASS: test123369
    volumes:
     - ./rmq-test/db-data:/var/lib/rabbitmq
    ports:
      - 5672:5672
      - 15672:15672

I keep getting the ThigsBoard server restarting with the error saying it cannot connect to RabbitMQ.

I tried changing the line: TB_QUEUE_RABBIT_MQ_HOST: localhost to TB_QUEUE_RABBIT_MQ_HOST: rabbitmq or using the ip address assigned to the docker container, and i keep getting this error in a loop:

Creating mytb_mytb_1 ... done
Attaching to mytb_mytb_1
mytb_1      | mkdir: cannot create directory ‘/data/db’: Permission denied
mytb_1      | The files belonging to this database system will be owned by user "thingsboard".
mytb_1      | This user must also own the server process.
mytb_1      | 
mytb_1      | The database cluster will be initialized with locale "C.UTF-8".
mytb_1      | The default database encoding has accordingly been set to "UTF8".
mytb_1      | The default text search configuration will be set to "english".
mytb_1      | 
mytb_1      | Data page checksums are disabled.
mytb_1      | 
mytb_1      | creating directory /data/db ... initdb: error: could not create directory "/data/db": Permission denied
mytb_1      | pg_ctl: database system initialization failed
mytb_1      | psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
mytb_1      |   Is the server running locally and accepting connections on that socket?
mytb_1      | psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
mytb_1      |   Is the server running locally and accepting connections on that socket?
mytb_1      | psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432" failed: No such file or directory
mytb_1      |   Is the server running locally and accepting connections on that socket?

You're welcome :)

By default, docker connects services within an internal network. To refence other services, you need to use the service name (or aliases...), localhost will not work.

Second issue posted doesn't have something to to with the rabbitmq connection, your mytb_1 container cannot access your data volume mapping. The service needs to have sufficient rights to write to the mapped directories

version: '2.2'
services:
  mytb:
    privileged: true
    restart: always
    depends_on: 
      - rabbitmq
    image: "thingsboard/tb-postgres"
    ports:
      - "9091:9090"
      - "1883:1883"
      - "7070:7070"
      - "5683-5688:5683-5688/udp"
    environment:
      TB_QUEUE_TYPE: rabbitmq
      TB_QUEUE_RABBIT_MQ_USERNAME: test
      TB_QUEUE_RABBIT_MQ_PASSWORD: test123369
      # Use the rabbitmq service name as a host instead of localhost
      TB_QUEUE_RABBIT_MQ_HOST: rabbitmq 
      TB_QUEUE_RABBIT_MQ_PORT: 5672
    volumes:        
      - ./.mytb-data:/data
      - ./.mytb-logs:/var/log/thingsboard
      # make sure that the service has sufficient rights to
      # write to the mapped directories
  rabbitmq:
    ... (rest of file left out)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM