I have the mysql database stored in /home/mysql
instead of /var/lib/mysql
. The directory used to be owned by mysql
. However, when I run the command docker-compose up
with this yml file:
version: '3'
services:
mariadb:
image: mariadb
restart: always
volumes:
- /home/mysql:/var/lib/mysql
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.4
environment:
- "ES_JAVA_OPTS=-Xms750m -Xmx750m"
- bootstrap.memory_lock=false
site:
build: .
volumes:
- "./app:/app"
links:
- mariadb:mysql
environment:
- DOCKER_IP=172.19.0.2
depends_on: ['elasticsearch','mariadb']
ports:
- "3000:3000"
The docker container is able to run, but the entire folder and files in /home/mysql
are owned by systemd-journal-remote
, which causes the node
server fails to connect to mariadb
. I have to stop the docker instance, restore the mysql folder ownership and delete ib_logfile0
and ib_logfile1
.
Why does mounting /home/mysql
cause such a fatal problem?
Update:
My solution is to add user: "mysql"
:
version: '3'
services:
mariadb:
image: mariadb
restart: always
volumes:
- /home/mysql:/var/lib/mysql
user: "mysql"
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.4
environment:
- "ES_JAVA_OPTS=-Xms750m -Xmx750m"
- bootstrap.memory_lock=false
site:
build: .
volumes:
- "./app:/app"
links:
- mariadb:mysql
environment:
- DOCKER_IP=172.19.0.2
depends_on: ['elasticsearch','mariadb']
ports:
- "3000:3000"
You should start Docker's container with
--user
parameter. If you do this and set the sameuid:gid
as owner of the MySQL storage you will no have problems with permissions. You have to check how exactly to do this in Docker Compose because I show you example for normal command line executionMost likely,
uid
of your usersystemd-journal-remote
is the same asuid
of usermysqld
in container. Check withls -n
. To avoid confusion, either use commonuid
s, perhaps test asroot:root
withchmod o+rwx
.