How to fix 'Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only' error in windows server 2019 with DockerProvider service

21.5k views Asked by At

I'm installed docker in windows server 2019 with DockerProvider I'm using this code

Install-Module DockerProvider
Install-Package Docker -ProviderName DockerProvider -RequiredVersion preview
[Environment]::SetEnvironmentVariable("LCOW_SUPPORTED", "1", "Machine")

after that I install Docker-Compose with this code

[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-Windows-x86_64.exe" -UseBasicParsing -OutFile $Env:ProgramFiles\Docker\docker-compose.exe

after that I use a docker compose file

version: "3.5"

services:


  rabbitmq:
    # restart: always
    image: rabbitmq:3-management
    container_name: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    networks:
      - myname
    # network_mode: host
    volumes: 
      - rabbitmq:/var/lib/rabbitmq



networks:
  myname:
    name: myname-network

volumes:
  rabbitmq:
    driver: local

everything is Ok up to here but after i call http://localhost:15672/ url in my browser rabbitmq crashes and I see this error in docker logs <container-id>

Cookie file /var/lib/rabbitmq/.erlang.cookie must be accessible by owner only

this .yml file is working correctly in docker for windows but after running the file in windows server, I see this error

6

There are 6 answers

1
alv On

Solution is to map a different volume where the cookie file will be created;

So for your example, not;

- rabbitmq:/var/lib/rabbitmq

but;

- rabbitmq:/var/lib/rabbitmq/mnesia
0
Gabriel Petrovay On

You also have the option to overwrite the command of the docker image to fix the issue it is complaining about. Assuming that your cookie file is /var/lib/rabbitmq/.erlang.cookie, replace the original docker image command, which is probably:

["rabbitmq-server"]

with:

["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"]

In your docker-compose file it will look like this:

...
image: rabbitmq:3-management
...
ports:
- "5672:5672"
- "15672:15672"
volumes:
- ...
command: ["bash", "-c", "chmod 400 /var/lib/rabbitmq/.erlang.cookie; rabbitmq-server"]

Of course, you introduce here some workaround/technical debt that you assume rabbitmq-server will stay like that in the future.

1
liuchanglong On
version: '3'

services:
  rabbitmq:
    image: rabbitmq:3-management
    hostname: rabbitmq
    ports:
      - 5672:5672
      - 15672:15672
    volumes:
      - ./rabbitmq1/data:/var/lib/rabbitmq
      - ./rabbitmq1/config:/etc/rabbitmq
    environment:
      RABBITMQ_ERLANG_COOKIE: "rabbitcookie"
      RABBITMQ_DEFAULT_USER: "admin"
      RABBITMQ_DEFAULT_PASS: "password"
    networks:
      rabbitmq-cluster:

networks:
  rabbitmq-cluster:
    driver: bridge

Here is my verified config file

If you want to see the verification results, please see hereenter image description here

0
obe6 On

In my case I deleted the previous file .erlang.cookie

ls -al
128 Apr  4 10:55 .
384 Apr  4 10:55 ..
 20 Apr  4 02:00 .erlang.cookie <= delete this 
192 Apr  4 10:55 mnesia

and restart docker (or nerdctl) compose

0
jinzuchi On

found .erlang.cookie file in your host directory, then type chmod 400 .erlang.cookie and restart rabbitmq docker, it should be fixed.

0
venu On

This issue showed up suddenly after I changed the dir/file permissions recursively on my Linux VM where Anylogic Cloud is running. This is how I fixed it.

  1. docker inspect rabbitmq
  2. Find the host directory for /var/lib/rabbitmq from the output of inspect. For example "Type": "bind", "Source": "/xx/xx/rabbitmq", "Destination": "/var/lib/rabbitmq",
  3. Navigate to the actual host directory/location and execute 'ls -al' command. It should list the cookie file. -rwxrwxrwx 1 Feb 8 16:00 .erlang.cookie
  4. Then type chmod 400 .erlang.cookie. You may restart rabbitmq container.