为什么运行docker容器后mysql数据所有权更改为systemd-journal-remote [英] Why did mysql data ownership change to systemd-journal-remote after running a docker container

查看:43
本文介绍了为什么运行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_logfile0ib_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":

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"

推荐答案

你应该使用 --user 参数启动 Docker 的容器.如果您这样做并将相同的 uid:gid 设置为 MySQL 存储的所有者,您将不会遇到权限问题.您必须检查如何在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆