Albeis
Albeis

Reputation: 1580

Docker-compose : mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (Errcode: 13 - Permission denied)

I'm having an issue when starting the db service with docker compose:

 version: '3'
 services:

 # Mysql DB
    db:
        image: percona:5.7
        #build: ./docker/mysql
        volumes:
          - "./db/data:/var/lib/mysql"
          - "./db/init:/docker-entrypoint-initdb.d"
          - "./db/backups:/tmp/backups"
          - "./shared/home:/home"   
          - "./shared/root:/home"  
        restart: unless-stopped
        environment:
            MYSQL_ROOT_PASSWORD: root
            MYSQL_DATABASE: db_name
            MYSQL_USER: user
            MYSQL_PASSWORD: pass
       ports:
       - "3307:3306"

I have tried everything with no luck:

"./db/data:/var/lib/mysql:rw"

Creating a dockerfile and create from build instead of image:

FROM percona:5.7

RUN adduser mysql
RUN sudo chown mysql /var/lib/mysql
RUN sudo chgrp mysql /var/lib/mysql

Also I have tried to add a user on db service:

user: "1000:50"

But any of those could solve that.. What I'm missing?

MySQL 5.7 installation error `mysqld: Can't create/write to file '/var/lib/mysql/is_writable'`

Upvotes: 18

Views: 38191

Answers (7)

br4nnigan
br4nnigan

Reputation: 739

Instead of changing the permissions to match the container user id you can map them while building the container: docker-compose build --build-arg UID=$(id -u) --build-arg GID=$(id -g)

Dockerfile:

RUN usermod  --uid $UID mysql
RUN groupmod --gid $GID mysql

Upvotes: 2

Mozar Silva
Mozar Silva

Reputation: 11

need permission to execute scripts in directory

sudo chown 999:999 ./db/data
sudo chmod +x ./db/data

Upvotes: 1

progonkpa
progonkpa

Reputation: 3950

I suffered this issue and it took quite some time to figure out what the culprit was.

In my case, I have a dual boot system Winblowz-Linux. My code of the problematic project was on a Windows filesystem.

Once I cloned the project into my Linux drive, on a ext4 filesystem, the problem went away.

Upvotes: 0

Alexander Yancharuk
Alexander Yancharuk

Reputation: 14531

According Dockerfile Percona 5.7 images runs under CentOS v8 and user mysql. Check the user ID (uid) and group ID (gid) inside container:

user@host$ docker run --rm -t percona:5.7.29 sh -c 'id'
uid=999(mysql) gid=999(mysql) groups=999(mysql)

Default user inside container uses 999 uid and gid. Than change your directory rights to 999:999:

sudo chown 999:999 ./db/data

This is an addition to Albeis answer.

Upvotes: 3

fireside68
fireside68

Reputation: 55

I spent a whole day with a similar (almost exactly) problem. I also changed ownership of the related files, only to see them get wiped out and come back with permissions issues. I changed the ownership of my curl-installed docker-compose executable. I didn't receive a bit of reprieve until adding the volumes to the .dockerignore, as was suggested in this Github issue reply.

Upvotes: 1

Albeis
Albeis

Reputation: 1580

I had to change ./db/data user:group to 999:999, so docker user is who is making the changes.

sudo chown 999:999 ./db/data

Upvotes: 13

6be709c0
6be709c0

Reputation: 8441

Make sure that the user who is running docker has access to ./db/data

# Not in the dockerfile
sudo chown $(whoami) ./db/data
sudo chgrp $(whoami) ./db/data

Docker tells you that you don't have the permissions, it might also mean that you need to verify that you shared volume ./db/data need to have the correct permissions.

Upvotes: 3

Related Questions