docker-library/rabbitmq

All the data is lost after I run `docker-compose down`. Is this expected behaviour?

agarwalkartik opened this issue · 3 comments

Here is my dockerfile for reference.

version: '3'
services:
    rabbitmq:
        image: 'rabbitmq:3-management'
        container_name: rabbitmq
        ports:
            - 5672:5672
            - 15672:15672
        volumes:
            - /rabbitmq-data/:/var/lib/rabbitmq/

I intend to persist the rabbitmq data to /rabbitmq-data/ on my host machine. I think that the data is stored there but somehow all the data is lost when I run docker-compose down. Shouldn't it persist even after that. If not then how can I achieve the same ?

Adding a hostname solves the issue.

version: '3'
services:
    rabbitmq:
        image: 'rabbitmq:3-management'
        container_name: rabbitmq
        hostname: "rabbit"
        ports:
            - 5672:5672
            - 15672:15672
        volumes:
            - /rabbitmq-data/:/var/lib/rabbitmq/

if hostname is not provided, it creates a random hostname each time service is restarted.

What to do if my bindings are always getting lost?

version: '3.8'

services:
  rabbitmq:
    image: 'rabbitmq:3.12.7-management'
    hostname: "rabbitmq"
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq
    ports:
      - '5672:5672'
      - '15672:15672'
    environment:
      RABBITMQ_DEFAULT_USER: 'rmuser'
      RABBITMQ_DEFAULT_PASS: 'rmpassword'

volumes:
  rabbitmq_data:

@lyf2000 if you have a way to reproduce the issue, please share it via a git repository. We have no idea how you are creating the bindings and other entities in your setup.

Normally I wouldn't follow up when someone does not provide enough information, but I decided to double-check this time. I took about 20 minutes to put the following project together: https://github.com/lukebakken/docker-library_rabbitmq-392

As expected, it works just fine.

Here's how I tested:

make up
make import
# check to see that queue and binding are created in management UI
make restart
# queue and binding are STILL there