dockerdocker-composerancher-desktop

Volumes permission denied when try to start docker container


I started use Rancher Desktop instead of Docker Desktop and faced the problem with permissions. I have a docker-compose file with the next content:

version: "3.2"
services:
  rabbitmq:
    image: rabbitmq:3.8-management-alpine
    container_name: 'rabbitmq'
    ports:
      - 5672:5672
      - 15672:15672
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest
    volumes:
      - ~/.docker-conf/rabbitmq/data/:/var/lib/rabbitmq/
      - ~/.docker-conf/rabbitmq/log/:/var/log/rabbitmq

But when I try to run rabbitmq container by execute docker-compose up rabbitmq the following error throws:

% docker-compose up rabbitmq
[+] Running 1/0
 ✔ Container rabbitmq  Created                                                                 0.0s 
Attaching to rabbitmq
rabbitmq  | chown: /var/lib/rabbitmq: Permission denied
rabbitmq exited with code 1
% 

My computer is Mac OS Monterey (M1).

It worked correctly when I used Docker Desktop. Do you have any ideas why Rancher Desktob has problems with permissions and how to fix it? Any help will be appreciated!

I tried to remove volumes section at all and set user: 'root' and this resolved this problem, but it's not good solution for me.

version: "3.2"
services:
  rabbitmq:
    image: rabbitmq:3.8-management-alpine
    container_name: 'rabbitmq'
    user: "root"
    ports:
      - 5672:5672
      - 15672:15672
    environment:
      RABBITMQ_DEFAULT_USER: guest
      RABBITMQ_DEFAULT_PASS: guest

I expect that my rabbitmq container will start properly without permissions error.


Solution

  • This all works just fine if you use Docker volumes rather than trying to bind-mount existing filesystem directories:

    services:
      rabbitmq:
        image: rabbitmq:3.8-management-alpine
        container_name: 'rabbitmq'
        ports:
          - 5672:5672
          - 15672:15672
        environment:
          RABBITMQ_DEFAULT_USER: guest
          RABBITMQ_DEFAULT_PASS: guest
        volumes:
          - rabbitmq-data:/var/lib/rabbitmq/
          - rabbitmq-log:/var/log/rabbitmq
    
    volumes:
      rabbitmq-data:
      rabbitmq-log:
    

    This works because when mounting a volume it takes on the ownership and permissions of the mountpoint.

    Using volumes is generally a more effective way to manage container storage (unless you explicitly need access to the underlying files).