Solve the problem that the directory mounted by docker cannot be read and written

Solve the problem that the directory mounted by docker cannot be read and written

Use the following command to create a container and mount the local /home/dock/Downloads directory to /usr/Downloads in the container:

[root@docker ~]# docker run -it -v /home/dock/Downloads:/usr/Downloads ubuntu /bin/bash

After creating on Centos, the following problems will occur

root@637fe9ea94f0:/usr/Downloads# ls
ls: cannot open directory '.': Permission denied

Solution:

The reason is that the security module selinux in CentOS7 has disabled the permissions.

There are several ways to solve the problem of no permissions on the mounted directory:

1. When running the container, add privileges to the container and add the --privileged=true parameter:

docker run -i -t -v /soft:/soft --privileged=true 637fe9ea94f0 /bin/bash

2. Temporarily turn off selinux:

setenforce 0

3. Add selinux rules and change the security text of the directory to be mounted

Supplement: After docker mounts the folder, it cannot be accessed and has no permissions

After entering docker run, the mounted folder cannot be accessed and there is no permission

For example:

sudo nvidia-docker run -p 8090:8888 -p 8091:80 -p 8092:6666 --name=pytorch0.4 -v ~/workspace:/root/workspace -i --shm-size 31G -t dsksd/pytorch:0.4.1 /bin/bash

The host's workspace folder is mounted with the container's /root/workspace folder, but data cannot be written to the workspace folder on the host. Because the owner of the folder is root at this time.

You can execute the command:

sudo chown -R $USER folder location (/workspace)

The folder can be read and written. However, you need to re-execute the above command after restarting.

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:
  • Docker View the Mount Directory Operation of the Container
  • Solve the problem of failure to mount files or directories using ./ relative path in docker run
  • Implementation of mounting NFS shared directory in Docker container
  • Docker - Summary of 3 ways to modify container mount directories
  • Docker mounts local directories and data volume container operations
  • Docker starts the elasticsearch image and solves the error after mounting the directory
  • Solution to the failure of docker windows10 shared directory mounting

<<:  CSS3 mobile vw+rem method to achieve responsive layout without relying on JS

>>:  Use neat HTML markup to build your pages

Recommend

Vue Learning - VueRouter Routing Basics

Table of contents 1. VueRouter 1. Description 2. ...

Implementation of Docker cross-host network (overlay)

1. Docker cross-host communication Docker cross-h...

Deeply understand how nginx achieves high performance and scalability

The overall architecture of NGINX is characterize...

Centos7.5 configuration java environment installation tomcat explanation

Tomcat is a web server software based on Java lan...

You really need to understand the use of CSS variables var()

When a web project gets bigger and bigger, its CS...

Complete steps to use samba to share folders in CentOS 7

Preface Samba is a free software that implements ...

Vue implements a small countdown function

Countdown function needs to be implemented in man...

Native js implements shopping cart logic and functions

This article example shares the specific code of ...

Detailed explanation of how to configure static IP in Centos8

After installing centos 8, the following error wi...

MySQL Series 7 MySQL Storage Engine

1. MyISAM storage engine shortcoming: No support ...

Linux server quick uninstall and install node environment (easy to get started)

1. Uninstall npm first sudo npm uninstall npm -g ...

Why is it slow when using limit and offset paging scenarios?

Let’s start with a question Five years ago when I...