Docker percona (mysql mariadb) container stops aft

2019-07-25 15:02发布

问题:

On Ubuntu 16.04 with Docker 17.05.0-ce I try to setup percona-mysql docker image with host directory mapping (volume). Here is image:

docker pull percona/percona-server:latest

And here is container run command:

docker run --name percona -e MYSQL_ROOT_PASSWORD=secret -v /home/myuser/db/files:/var/lib/mysql -p 6603:3306 -d percona/percona-server:latest mysql -h docker_host_ip -P 6603

The problem is that container immediately stop after this command - but when I not use -v ... parameter (volume mapping) then container starts without problems. How to solve this problem?

This problem can potentially also be on mysql or mariadb images.

回答1:

Solution

Type following commands on your host:

cd /home/myuser/db
sudo chown 1001:0 files

Then run container again and thats all :)

Way

  1. After fail of running, I look on logs: docker logs percona and see that mysql has no permissions to write to dir /var/lib/mysql
  2. I run container without volume: docker run --name percona -e MYSQL_ROOT_PASSWORD=secret -p 6603:3306 -d percona/percona-server:latest mysql -h docker_host_ip -P 6603
  3. I login to container: docker exec -it percona /bin/bash
  4. I type: cd /var/lib
  5. After execute ls -l i see near mysql dir following row: drwxr-xr-x 5 mysql root 4096 Oct 6 14:39 mysql. This mean that owner is mysql and group is root.
  6. I get mysql user UID by id -u mysql (I get 1001)
  7. I check by groups mysql that mysql has one group (root). So to get root GID I type id -g mysql (I get 0)
  8. The chown command allow to set file UID:GID even for users which doesnt exist (!) so we not need to create user mysql on host. So after run chown ... on host, folder files have exact the same user and group that mysql inside container expect.