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.
Solution
Type following commands on your host:
cd /home/myuser/db
sudo chown 1001:0 files
Then run container again and thats all :)
Way
- 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
- 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
- I login to container:
docker exec -it percona /bin/bash
- I type:
cd /var/lib
- 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
.
- I get mysql user UID by
id -u mysql
(I get 1001)
- I check by
groups mysql
that mysql has one group (root). So to get root GID I type id -g mysql
(I get 0)
- 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.