[英]MySQL in Docker mounted directory permissions are messed up on external SSD
I'm running MySQL inside a docker image and I'm mounting a directory from the host inside the container to have the database persisted ./db:/var/lib/mysql
.我在 docker 映像中运行 MySQL 并且我正在从容器内的主机挂载一个目录以使数据库持久化./db:/var/lib/mysql
。
Since the data got really big, I had to move everything to my external SSD.由于数据变得非常大,我不得不将所有东西都移到我的外部 SSD 上。 Now it seems that the permissions of the mounted directory are messed up.现在看来挂载目录的权限搞乱了。 When I let MySQL container initialize the ./db
directory, it's all good.当我让 MySQL 容器初始化./db
目录时,一切正常。 But if I stop the containers, remove the external SSD, and connect it back and spin up the containers again, the MySQL container keeps restarting, logging things like:但是,如果我停止容器,移除外部 SSD,然后重新连接并再次启动容器,MySQL 容器会继续重新启动,记录如下内容:
chown: changing ownership of '/var/lib/mysql/._binlog.000004': Operation not permitted
ls -l
: drwxrwxrwx@ 1 amir staff 131072 May 5 21:25 db
. ls -l
: drwxrwxrwx@ 1 amir staff 131072 May 5 21:25 db
。docker -v
: Docker version 19.03.8, build afacb8b
. docker -v
: Docker version 19.03.8, build afacb8b
。docker-compose -v
: docker-compose version 1.25.4, build 8d51620a
docker-compose -v
: docker-compose version 1.25.4, build 8d51620a
docker-compose.yml
: docker-compose.yml
:
version: "3" services: db: image: mysql volumes: -./db:/var/lib/mysql restart: always ports: - "3306:3306" environment: MYSQL_ROOT_PASSWORD: password networks: - projectnetwork networks: projectnetwork:
Any hints to how I can solve this problem would be greatly appreciated:) Thank you!任何有关如何解决此问题的提示将不胜感激:) 谢谢!
Alright, I'm not sure if this is the best way to solve this, but I can get around the issue with this at the moment.好吧,我不确定这是否是解决这个问题的最佳方法,但我现在可以解决这个问题。 Please let me know if this is totally dumb and there are better solutions.请让我知道这是否完全愚蠢并且有更好的解决方案。
I tried running the container with docker
itself and passing --user "$(id -u):$(id -g)"
and it worked.我尝试使用docker
本身运行容器并传递--user "$(id -u):$(id -g)"
并且它有效。
Unfortunately, we can't do sub bash commands in docker-compose
file, so I had to create my own script that sets an environment variable and runs docker-compose:不幸的是,我们不能在docker-compose
文件中执行子 bash 命令,所以我必须创建自己的脚本来设置环境变量并运行 docker-compose:
DOCKER_COMPOSE_USER=$(id -u):$(id -g) docker-compose up -d
And in docker-compose.yml
:在docker-compose.yml
中:
user: ${DOCKER_COMPOSE_USER}
That did the trick!那成功了!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.