Mysql: chown: cannot read directory '/var/lib/mysql/': Operation not permitted

Created on 3 Aug 2016  路  9Comments  路  Source: docker-library/mysql

in my compose file,in docker-machine(mac)

 volumes:
    - "./datadir:/var/lib/mysql"

it gives

mysql_1 | chown: cannot read directory '/var/lib/mysql/': Operation not permitted

Most helpful comment

        ...
        volumes:
            - ./database:/var/lib/mysql:rw
        user: mysql
        ...
  • should solve the problem as it does in my case.

All 9 comments

MySQL will by default try to make itself the owner of datadir if it isn't already, which is probably denied by your system.
You could try adding the --user argument to the container to change the user the server is run as, or maybe change the permissions on ./datadir

i tried

user: ftp
user: root
user: mysql

in the docker-compose, no luck

how to change the permissions on datadir?

I did the same thing but with the socket.

volumes:
  - /var/run/mysqld:/var/run/mysqld

To get it working I had to "chown 999:0 /var/run/mysqld" on the host OS. So maybe try that with your ./datadir.

I didn't have to do this with the postgres image for some reason.

The user is resolved to the user ids in the image; have you tried a user id like user: 1000?

In my case, that was SELINUX blocking access to host shared directory. Don't disable SELINUX :bomb: , add rules instead :+1: or you can run docker as a privileged user. Details here:
http://stackoverflow.com/questions/24288616/permission-denied-on-accessing-host-directory-in-docker

@yosifkit How we can add user ?
I am on mac with kinematic if I enable custom volumes from UI Kitematic mysql got stop and I get issue , I have seen your msg about user parameters but I dont understand how I can add via kitematic ?

Closing since this original issue is solved.

In the future, these sorts of questions/requests would be more appropriately posted to the Docker Community Forums, the Docker Community Slack, or Stack Overflow. Thanks!

        ...
        volumes:
            - ./database:/var/lib/mysql:rw
        user: mysql
        ...
  • should solve the problem as it does in my case.

If others solution doesn't work, and you are on Docker Engine for MacOs.
Try to re-add the folder of your project into Files sharing. (Docker -> Settings -> Ressources ->Files sharing )

Was this page helpful?
0 / 5 - 0 ratings