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:
Then run container again and thats all :)
Way
docker logs percona
and see that mysql has no permissions to write to dir/var/lib/mysql
docker run --name percona -e MYSQL_ROOT_PASSWORD=secret -p 6603:3306 -d percona/percona-server:latest mysql -h docker_host_ip -P 6603
docker exec -it percona /bin/bash
cd /var/lib
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 ismysql
and group isroot
.id -u mysql
(I get 1001)groups mysql
that mysql has one group (root). So to get root GID I typeid -g mysql
(I get 0)chown
command allow to set file UID:GID even for users which doesnt exist (!) so we not need to create usermysql
on host. So after runchown ...
on host, folderfiles
have exact the same user and group that mysql inside container expect.