In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how Docker sets directory permissions when creating containers. Xiaobian thinks it is quite practical, so share it with you for reference. I hope you can gain something after reading this article.
Yesterday when writing projects need to use MySQL derivative version percona, I want to use Doker to install. It took a night of stomping, but this morning it was solved. It is recorded here.
The reason for this pit is that I am not sensitive to linux directory permissions. My system is ubuntu16.04, running docker pull percona pull mirror everything works fine.
After pulling, enter docker images to view all images, and the display is normal:
Then I create the container with the command (execute without newlines):
docker create --name percona -v /data/mysql-data:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root percona:lates
What this command means is that I create a container named percona, map my local directory/data/mysql-data to the docker directory/var/lib/mysql and specify port 3306, then set the database root password to root, and finally percona:latest specifies the version I pulled above.
Because the database in docker container is just a mirror, it can be understood that it does not really exist. The function of mapping to my local directory is that the data stored in docker to/var/lib/mysql directory can be stored synchronously to my local/data/mysql-data directory. This ensures that the data is not lost, but also convenient for my local operations.
Command parameters do not understand the official documentation or search a docker video tutorial, there are explanations. Then I open this container, docker start percona. After opening it, query all running containers docker ps. At this time, there is a problem:
The server is empty, i.e., the server does not have a server. Then I checked all the containers, both working and not working. docker ps -a, shown as follows:
It turned out that the port was not successfully bound, so it did not run! automatically exited every time it runs
Then I looked at the docker logs and typed the docker logs container id, which looked like this:
Note: 71 here is the first two digits of the container_id of my container, docker supports this simplified way of writing.
Log error saying I don't have create and write permissions to/var/lib/mysql directory in container.
Now find the cause of this problem, but search a night did not solve, have to say that some irresponsible online water paste is really pit!
Finally found a solution in the morning:
That is, check whether the owner of my local directory is the same user as the owner of the/var/lib/mysql directory in the docker container.
docker run -ti --rm --entrypoint="/bin/bash" percona -c "whoami && id"
The effect of this command is to view the owner of the container, displayed as:
Then type (cannot wrap):
docker run -ti --rm -v /data/mysql-data:/var/lib/mysql --entrypoint="/bin/bash" percona -c "ls -la /var/lib/mysql"
The purpose of this command is to view the owner of this directory when mapping local volumes
This is why mysql users report permission errors when accessing directories in docker! Because the owner of the local mapping directory is root, and the owner of the/var/lib/mysql directory in the docker container is mysql user,uid is 999!
Then the solution is to assign the owner of the current directory to uid 999, the mysql user, and restart the container.
About "Docker how to set directory permissions when creating containers" This article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.