dockerdocker-composerabbitmqdocker-for-windowsdocker-desktop

RabbitMQ Docker Container Error: Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces


I am having a problem with running rabbitmq from within Docker on Windows Server 1709 (Windows Server core edition).

I am using docker-compose to create the rabbitmq service. If I run the docker-compose on my local computer, everything works fine. When I run the docker-compose on the windows server (where docker has been set to docker lcow support on windows) I get the above mentioned error multiple times occurring the in the logs. Namely this error is:

Error when reading /var/lib/rabbitmq/.erlang.cookie: eacces

It is worth noting that I receive this error even if I just do a manual pull of rabbitmq and a manual run with docker run -itd --rm --name rabbitmq rabbitmq:3-management

I am able to bash into the container for a short while before it crashes and exits and I see the following:

root@localhost:~# ls -la
---------- 2 root root   20 Jan  5 12:18 .erlang.cookie

On my localhost, the permissions look like this (which is correct):

root@localhost:~# ls -la 
-r-------- 1 rabbitmq rabbitmq   20 Dec 28 00:00 .erlang.cookie

I can't understand why the permission structure is broken on the server.

Is it possible that this is an issue with LCOW support on Windows Server 1709 with Docker for Windows? Or is the problem with rabbitmq?

For reference here is the docker compose file used:

version: "3.3"
services:

  rabbitmq:
    image: rabbitmq:3-management
    container_name: rabbitmq
    hostname: localhost
    ports: 
      - "1001:5672"
      - "1002:15672"
    environment:
      - "RABBITMQ_DEFAULT_USER=user"
      - "RABBITMQ_DEFAULT_PASS=password"
    volumes:
      - d:/docker_data/rabbitmq:/var/lib/rabbitmq/mnesia
    restart: always

For reference here is the docker information where there error is happening.

docker info

Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 1
Server Version: 17.10.0-ee-preview-3
Storage Driver: windowsfilter (windows) lcow (linux)
 LCOW:
Logging Driver: json-file
Plugins:
 Volume: local
 Network: ics l2bridge l2tunnel nat null overlay transparent
 Log: awslogs etwlogs fluentd json-file logentries splunk syslog
Swarm: inactive
Default Isolation: process
Kernel Version: 10.0 16299 (16299.15.amd64fre.rs3_release.170928-1534)
Operating System: Windows Server Datacenter
OSType: windows
Architecture: x86_64
CPUs: 4
Total Memory: 7.905GiB
Name: ServerName
Docker Root Dir: D:\docker-root
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Experimental: true
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false

docker version

Client:
 Version:      17.10.0-ee-preview-3
 API version:  1.33
 Go version:   go1.8.4
 Git commit:   1649af8
 Built:        Fri Oct  6 17:52:28 2017
 OS/Arch:      windows/amd64

Server:
 Version:      17.10.0-ee-preview-3
 API version:  1.34 (minimum version 1.24)
 Go version:   go1.8.4
 Git commit:   b8571fd
 Built:        Fri Oct  6 18:01:48 2017
 OS/Arch:      windows/amd64
 Experimental: true

Solution

  • I struggled with same problem when run RabbitMQ inside AWS ECS container

    Disclaimer: I didn't check this behavior in detail and that is only my assumption, so the problem cause may be wrong, but at least solution is working

    It feels like RabbitMQ creating .erlang.cookie file on container start if it doesn't exist. And if inside-container user is root:

    ...
      rabbitmq:
        image: rabbitmq:3-management
        # set container user to root
        user: 0:0
    ...
    

    then .erlang.cookie will be created with root permissions. But RabbitMQ starting child processes with rabbitmq user permissions. And .erlang.cookie is not writeable (editable) in this case.

    To avoid this problem, I created custom image with existing .erlang.cookie file using Dockerfile:

    ARG COOKIE_VALUE=SomeDefaultRandomString01
    FROM rabbitmq:3.11-alpine
    
    ARG COOKIE_VALUE=$COOKIE_VALUE
    
    RUN printf 'log.console = true\nlog.console.level = warning\nlog.default.level = warning\nlog.connection.level = warning\nlog.channel.level = warning\nlog.file.level = warning\n' > /etc/rabbitmq/conf.d/10-logs_to_stdout.conf && \
        printf 'loopback_users.guest = false\n' > /etc/rabbitmq/conf.d/20-allow_remote_guest_users.conf && \
        printf 'management_agent.disable_metrics_collector = true' > /etc/rabbitmq/conf.d/30-disable_metrics_data.conf && \
        chown rabbitmq:rabbitmq /etc/rabbitmq/conf.d/* && mkdir -p /var/lib/rabbitmq/ && \
        echo "$COOKIE_VALUE" > /var/lib/rabbitmq/.erlang.cookie && chmod 400 /var/lib/rabbitmq/.erlang.cookie && \
        chown -R rabbitmq:rabbitmq /var/lib/rabbitmq
    

    where .erlang.cookie value may be any random string, but it should be same for all nodes in RabbitMQ cluster (extra information here).