昨天,今天,明天,每天的每天,你是否都多懂得一点点...

星期三, 八月 22, 2018

[网络技术] Handling files permission in docker containers with mounted volume

Tags: Docker, mysql, file permssion

I am recently moving away from Azure Mysql server to a local mysql server on VM.

To protect from data losing, I store mysql files on my VM and use -v to mount it to docker container. 

[bash]
 docker run \
            --name mysql \
            --network wp-net \
            --network-alias mysql-host \
            -v $PWD/mysql:/var/lib/mysql
            -e MYSQL_ROOT_PASSWORD=root \
            mysql:5.7.22
[/bash]

I would like to add all this files to git repo so that I can push them to remote regularly. But when I tried to do git init, permission is denied.

The mysql files are created by mysql container, and the user and group are both mysql. But when I view the files from the host machine. both user and mysql are 999.


To resolve this issue, I changed the files' group to my host user's group. 

[bash]
chown -R 999:fennng mysql
[/bash]

Then I updated the files permissions so that the host user can access it.

Within the mysql folder, run
[bash]
            sudo find . -type d -exec chmod 775 {} \;
            sudo find . -type f -exec chmod 664 {} \; 
[/bash]


Now both 999 and user's in fennng group can access these files.

It's not a great solution, but it's much safer than setting everything to 777.



没有评论:

其它博客地址

此博客的同步博客地址: http://fengnz.wordpress.com
这里进入我的MSN SPACE.