Sunday, February 27, 2022

[SOLVED] Volumes in Docker in Fedora permission denied

Issue

I'm trying to set up Docker with my Laravel project on Fedora 30. I want to set up mariadb container. This is from my docker-compose.yml file

mysql-db:
    image: mariadb:10.4.6-bionic
    container_name: mysql-db
    volumes:
      - ./run/var:/var/lib/mysql:Z
    environment:
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_USER=${DB_USERNAME}
      - MYSQL_PASSWORD=${DB_PASSWORD}
    ports:
      - 3306:3306
    networks:
      backend:
        aliases:
          - db

networks:
  backend:
    name: backend-network

But when I run docker-compose up I get this errors.

mysql-db       | find: '/var/lib/mysql/': Permission denied
mysql-db       | chown: changing ownership of '/var/lib/mysql/': Permission denied
mysql-db exited with code 1

I think it is problem with SELinux, as I had permission denied problems with my php-apache container. And I solved them by adding Z at the end of volumes line. I tried that here too, but it doesn’t seem to work.


Solution

It looks like I needed to set up value for MYSQL_ROOT_PASSWORD in environment. Now it happens to work :)



Answered By - Danilo Petkovic
Answer Checked By - David Goodson (WPSolving Volunteer)