7
votes

I'm running docker in Ubuntu and trying to create and run a MySql container. I want to use a mounted network share for the data directory. I am trying the following docker run command, but I'm having issues with permissions. How do I fix this?

root@jarvis:/mnt/wayne/mysql-data$ sudo docker run -it -p 3306:3306 -e MYSQL_ROOT_PASSWORD=admin -v /mnt/wayne/mysql:/var/lib/mysql/ --name mysqlserver mysql/mysql-server

[Entrypoint] MySQL Docker Image 8.0.20-1.1.16
[Entrypoint] Initializing database
2020-06-08T21:43:25.253898Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.20) initializing of server in progress as process 22
2020-06-08T21:43:25.281460Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-06-08T21:43:27.815075Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)
2020-06-08T21:43:29.851875Z 0 [ERROR] [MY-010295] [Server] Could not set file permission for ca.pem
2020-06-08T21:43:29.852970Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2020-06-08T21:43:29.854806Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-06-08T21:43:31.947298Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
6
can you please check your MySQL image version if it 5.7 then upgrade it to mysql:5.7.16Dupinder Singh
@Brain what kind of network share are you using? there is many protocols out therec4f4t0r
I am using CIFsBrian

6 Answers

2
votes

You use CIFs for network mount means the remote server is windows right? My answer is based on this assumption.

The latest mysql docker image has a user named mysql and its uid=27,gid=27 You verify this by mounting an empty folder as data_dir. You will see that the files created by mysql container has user and group is as 27. Hence the mysql container expects files with uid/gid(owner userid and owner group id) as 27 in its data_dir. But the files that you mounted from the windows share has uid/gid which belongs to the user that executes mount command in ubuntu. This is the default behavior of mount command.

To solve this you need to pass "uid=27,gid=27" parameters to the Linux mount command.

For instance

sudo mount -t cifs -o username=windows-username,uid=27,gid=27 //WIN_SHARE_IP/ /mnt/wayne

You can have look here for further details

I must say it is unlikely to run mysql over a network share. It won't perform well.

2
votes

This is not exactly with MySQL but I hope it can give you an idea, I basically use this for testing against a MySQL database from my local environment, for this I use docker-compose and MariaDB, I configure the "data-dir" as a volume so that I can stop/start the docker container without the need to "seed" every time the database.

This is the content of the /your/path/docker-compose.yml file:

---
version: '3'
services:
  mariadb:
    image: mariadb:10.4.13
    container_name: mariadb
    restart: always
    ports:
      - 13306:3306
    environment:
      MYSQL_DATABASE: world
      MYSQL_ROOT_PASSWORD: test
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - ${PWD}/mariadb/db/:/var/lib/mysql

In the same directory, I have the volume directory /your/path/mariadb/db

Then to bring up the container I use:

$ docker-compose up

From the docker-compose.yml has you can see I use port 13306 therefore for testing/connection I use:

$ mysql -h 127.0.0.1 -P13306 -uroot -p

All the data (databases) will be in /your/path/mariadb/db

If you run into the same "permissions" problem:

mysqld: Cannot change permissions of the file 'ca.pem' (OS errno 1 - Operation not permitted)

Try to change the permissions of your volume/mount point, for example:

chmod -R 777 /your/volume/mount_point
0
votes

okay, I tried this and google also, what I found is

https://github.com/docker-library/mysql/issues/302#issuecomment-308745834

So basically if you are using mysql:5.7 then upgrade to mysql:5.7.16.

And if this doesn't help then I have one more solution.

Basically the problem is you are sharing dir to container -v /mnt/wayne/mysql:/var/lib/mysql/ but you ubuntu is not giving permission to access the /mnt/wayne/mysql dir. so give admin permission to this location or you can create a docker user chown and chmode.

Basically give permission to the host machine directory. so that docker container can access it.

and One more thing give permission to the docker container dir also, that is showing in your error

The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.

Create a user in a docker container which have chown and chmod permissions to the dir /var/lib/mysql/.

if you are using dockerfile to create mysql container then use these following 2 lines in it

FROM mysql:5.7.16
WORKDIR /app
RUN chown -R admin:admin /app
RUN chmod 755 /app
USER admin
CMD ["Your command"] 
0
votes

To operate normally, MariaDB or MySQL needs to set some permissions on their own files. Some external file systems (such as FTP and many others) do not support these features. You need to use a file system which supports these features.

0
votes

there is a permission issue to access the mounted volume. Please read the documentation about use volumes:

https://docs.docker.com/storage/volumes/#use-a-volume-driver

0
votes

For NFSv3 Partition:

$ docker service create -d \ --name nfs-service \ --mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,volume-opt=o=addr=10.0.0.10' \ nginx:latest

Or check the CA.pem file permissions (use chmod 777 /path/to/ca.pem)

For NFSv4 Partition:

docker service create -d \ --name nfs-service \ --mount 'type=volume,source=nfsvolume,target=/app,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/var/docker-nfs,"volume-opt=o=10.0.0.10,rw,nfsvers=4,async"' \ nginx:latest

Check https://docs.docker.com/storage/volumes/#use-a-volume-driver