問題描述
我將 mysql 數(shù)據(jù)庫存儲在 /home/mysql
而不是 /var/lib/mysql
.該目錄曾經(jīng)屬于 mysql
.但是,當(dāng)我使用這個 yml 文件運行命令 docker-compose up
時:
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"
docker容器可以運行,但是/home/mysql
中的整個文件夾和文件都歸systemd-journal-remote
所有,導(dǎo)致node
服務(wù)器無法連接到 mariadb
.我必須停止 docker 實例,恢復(fù) mysql 文件夾所有權(quán)并刪除 ib_logfile0
和 ib_logfile1
.
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
.
為什么掛載/home/mysql
會導(dǎo)致如此致命的問題?
Why does mounting /home/mysql
cause such a fatal problem?
更新:
我的解決辦法是添加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"
推薦答案
您應(yīng)該使用 --user
參數(shù)啟動 Docker 的容器.如果您這樣做并設(shè)置與 MySQL 存儲的所有者相同的 uid:gid
,您將不會遇到權(quán)限問題.您必須檢查如何在 Docker Compose 中準確執(zhí)行此操作,因為我向您展示了正常命令行執(zhí)行的示例
You should start Docker's container with --user
parameter. If you do this and set the same uid: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 execution
這篇關(guān)于為什么運行docker容器后mysql數(shù)據(jù)所有權(quán)改為systemd-journal-remote的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!