为什么运行docker容器后mysql数据所有权改为syste

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

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

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

基础教程推荐