Why did mysql data ownership change to systemd-journal-remote after running a docker container(为什么运行docker容器后mysql数据所有权改为systemd-journal-remote)
问题描述
我将 mysql 数据库存储在 /home/mysql
而不是 /var/lib/mysql
.该目录曾经属于 mysql
.但是,当我使用这个 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
所有,导致node
服务器无法连接到 mariadb
.我必须停止 docker 实例,恢复 mysql 文件夹所有权并删除 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
会导致如此致命的问题?
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"
推荐答案
您应该使用 --user
参数启动 Docker 的容器.如果您这样做并设置与 MySQL 存储的所有者相同的 uid:gid
,您将不会遇到权限问题.您必须检查如何在 Docker Compose 中准确执行此操作,因为我向您展示了正常命令行执行的示例
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
这篇关于为什么运行docker容器后mysql数据所有权改为systemd-journal-remote的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么运行docker容器后mysql数据所有权改为syste


- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- SQL 临时表问题 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01