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

Pure CSS to adjust Div height according to adaptive width (percentage)

Under the requirements of today's responsive ...

vue-cli4.5.x quickly builds a project

1. Install vue-cli npm i @vue/cli -g 2. Create a ...

Tutorial on installing and uninstalling python3 under Centos7

1. Install Python 3 1. Install dependency package...

A very detailed summary of communication between Vue components

Table of contents Preface 1. Props, $emit one-way...

Detailed explanation of nginx configuration file interpretation

The nginx configuration file is mainly divided in...

VMware and CentOS system installation method to reset the root password

Today's Tasks 1. Choice of Linux distribution...

Vue implements fuzzy query-Mysql database data

Table of contents 1. Demand 2. Implementation 3. ...

Classes in TypeScript

Table of contents 1. Overview 2. Define a simple ...

Example code for implementing a simple search engine with MySQL

Table of contents Preface Introduction ngram full...

The concept of MySQL tablespace fragmentation and solutions to related problems

Table of contents background What is tablespace f...

In-depth understanding of Worker threads in Node.js

Table of contents Overview The history of CPU-bou...

Front-end JavaScript thoroughly understands function currying

Table of contents 1. What is currying 2. Uses of ...

Nginx http health check configuration process analysis

Passive Check With passive health checks, NGINX a...