Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySql docker container not starting when using a network share for data directory

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.
like image 944
Brian Avatar asked Jun 08 '20 21:06

Brian


People also ask

Can you Dockerize database?

Docker is great for running databases in a development environment! You can even use it for databases of small, non-critical projects which run on a single server.


Video Answer


2 Answers

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.

like image 188
Mehmet Sunkur Avatar answered Sep 30 '22 12:09

Mehmet Sunkur


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
like image 23
nbari Avatar answered Sep 30 '22 12:09

nbari