Home>Article>Operation and Maintenance> What to do if docker v doesn't work
Solutions for docker v not working: 1. Add privileges to the container when running the container; 2. Temporarily turn off selinux; 3. Add selinux rules and add the directory to be mounted to the whitelist.
The operating environment of this article: ubuntu 18.04 system, Docker version 20.10.11, Dell G3 computer.
What should I do if docker v does not work?
About the problem that the service cannot be started after docker -v is mounted
I am learning docker recently and made a simple nginx image.
Due to the need to make a playable nginx. Therefore, the configuration files in the container need to be mounted on the host for easy operation.
After working on it for a while, I found that docker run added the -v attribute. The service will not start.
I have been troubled for a while and took a look at mounting this thing.
Finally found the cause of the problem, record it here. The reason is that the security moduleselinuxin CentOS7 disables permissions. There are at least the following three ways to solve the problem of the mounted directory not having permissions:
1. When running the container, Add privileges to the container:
Example: docker run -i -t–privileged=true-v /home/docs:/src waterchestnut/nodejs:0.12.0
2, temporarily close selinux:
Example: su -c
Execute afterwards:
docker run -i -t -v /home/docs:/src waterchestnut/nodejs:0.12.0
Note: Remember to re-enable selinux later, command: su -c "setenforce 1 ”
3, add selinux rules and add the directory to be mounted to the whitelist:
Example: chcon -Rt svirt_sandbox_file_t /home/docs
Execute after:
docker run -i -t -v /home/docs:/src waterchestnut/nodejs:0.12.0
After you have the mounting permission, you can start successfully.
Recommended learning: "Docker Video Tutorial"
The above is the detailed content of What to do if docker v doesn't work. For more information, please follow other related articles on the PHP Chinese website!