Solution to the docker command exception "permission denied"

Solution to the docker command exception "permission denied"

In Linux system, newly install docker and enter the command, such as: docker images

The result was abnormal.

Simply put, the current user's connection is rejected.

Solution 1:

Use administrator privileges, add sudo before the command

Solution 2:

Add the current user to the docker user group

sudo groupadd docker #Add the docker user group. This user group should already exist. sudo gpasswd -a $USER docker #Add the current user to the docker user group. newgrp docker #Update the user group docker.

Then execute docker images

This can be used normally

Supplement: Docker -v has no permission for the mounted directory. Solution to Permission denied

Description of the situation

Today I am using docker run -d -p 9091:8080 -v /home/daniu/docker/tomcat/webapps/:/usr/local/tomcat/webapps/ --name managertomcat daniu/mytomcat

After mounting the path, enter the container

root@08066d03a043:/usr/local/tomcat# cd webapps/
root@08066d03a043:/usr/local/tomcat/webapps# ls
ls: cannot open directory '.': Permission denied
root@08066d03a043:/usr/local/tomcat/webapps#

When viewing webapps, it prompts that there is no permission.

reason:

The security module selinux in centos7 disabled the permissions.

There are three ways to solve it:

1. Add --privileged=true at runtime

[daniu@localhost tomcat]$ docker run -d -p 9091:8080 -v /home/daniu/docker/tomcat/webapps/:/usr/local/tomcat/webapps/ --privileged=true --name managertomcat xuhaixing/mytomcat
c512137b74f3366da73ff80fc1fd232cc76c95b52a4bab01f1f5d89d28185b28
[daniu@localhost tomcat]$ ls

2. Temporarily turn off selinux and then turn it on again

[daniu@localhost tomcat]# setenforce 0
[daniu@localhost tomcat]# setenforce 1

3. Add linux rules and add the directory to be mounted to the selinux whitelist

# The format for changing security context is as follows: chcon [-R] [-t type] [-u user] [-r role] File or directory options without parameters: 
-R: All directories under this directory are also modified at the same time; 
-t: followed by the type field of the security document, for example httpd_sys_content_t; 
-u : followed by identity identification, for example system_u; 
-r: The color of the following street, for example system_r
implement:
chcon -Rt svirt_sandbox_file_t /home/daniu/docker/tomcat/webapps/

The above is my personal experience. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM. If there are any mistakes or incomplete considerations, please feel free to correct me.

You may also be interested in:
  • Solution to the error TNS: permission denied when Oracle starts listening in Linux
  • Solution to Apache startup error: Permission denied: httpd: could not open error log file
  • Solution to Permission denied in Python
  • Solution to Permission denied

<<:  MySQL database deletes duplicate data and only retains one method instance

>>:  HTML Frameset Example Code

Recommend

W3C Tutorial (7): W3C XSL Activities

A style sheet describes how a document should be ...

Vue3 (V) Details of integrating HTTP library axios

Table of contents 1. Install axios 2. Use of axio...

MySQL Interview Questions: How to Set Up Hash Indexes

In addition to B-Tree indexes, MySQL also provide...

Introduction to Linux environment variables and process address space

Table of contents Linux environment variables and...

Pitfall notes of vuex and pinia in vue3

Table of contents introduce Installation and Usag...

Detailed explanation of Apache SkyWalking alarm configuration guide

Apache SkyWalking Apache SkyWalking is an applica...

Detailed explanation of Docker container data volumes

What is Let’s first look at the concept of Docker...

In-depth explanation of the style feature in Vue3 single-file components

Table of contents style scoped style module State...

JavaScript source code for Elimination

JavaScript to achieve the source code download ad...

The url value of the src or css background image is the base64 encoded code

You may have noticed that the src or CSS backgroun...

What you need to know about responsive design

Responsive design is to perform corresponding ope...

Comprehensive explanation of CocosCreator hot update

Table of contents Preface What is Hot Change Coco...