JoeTortuga
JoeTortuga

Reputation: 376

In Docker for Windows, permissions denied for mkdir/chown

I'm working on developing a ghost blog and deploying it as a docker container. Since one of the goals of my project is to develop themes and other things with live data, I've created a volume mount for the /var/lib/ghost directory as suggested by the ghost docker image.

The ghost docker image mounts the drive fine, but when it tries to chown the file, it gets a permission denied error. I'm running the Creator update of Windows 10, and the latest Docker for Windows (ie, Windows 10 Pro versin 1703, and Docker version 17.03.1-ce-win5)

As a test, I followed this procedure, at both home and work (where I'm on the previous version of windows 10):

  1. Create a Project\site directory in C:\users\joe\
  2. Place the docker-compose.yml file below the directory:
  3. Run docker-compose up

docker-compose.yml

version: '3'
services:
  blog:
    image: ghost
    volumes:
      - ./blog:/var/lib/ghost
    ports:
      - "2368:2368"

On my work machine, it creates the blog directory, and populates it with the themes and content as expected from a ghost blog.

On my home machine, I get this error:

ERROR: for blog Cannot start service blog: error while creating mount source path '/C/Users/joe/Projects/site/blog': mkdir /C/Users/joe/Projects/site/blog: permission denied ERROR: Encountered errors while bringing up the project.

if I make the directory myself, and run docker-compose.yml again, I get this error:

blog_1 | chown: changing ownership of '/var/lib/ghost': Permission denied

site_blog_1 exited with code 1

Mounting directories definitely works, I've run the alpine ls /data example shown on the settings for shared drives in Docker for Windows.

I've compared the settings in docker, on the virtual networks, on the directories between home and work -- the only differences I can find are because work is on a Domain, and has a different username, and that my version of windows is 1607.

I don't know if this is a bug, a bad interaction between current windows && docker, or something I've done wrong locally. I admit I'm leaning toward the latter because I can find no documentation about this anywhere.

Upvotes: 4

Views: 43809

Answers (4)

Gilbert
Gilbert

Reputation: 3304

If you are getting an error in docker saying:

mkdir: can't create directory 'l': Permission denied

When trying to create a folder or file in a shared folder on Windows, this is for you.

Make sure you have the full control permissions to the shared folder, to achieve this:

To check if you have full control permissions, from Windows File Manager, go to Network, select the drive and try creating a file from inside the selected folder.

select drive from network path

If you get an error saying you don't have permissions, then it means you have read permissions but no write permissions.

In this case, from the folder in the network path, right click and select properties -> select "Sharing" tab -> click "Advanced Sharing".

Select Advanced Sharing

From the Advanced Sharing window, click "Permissions".

Permissions window

From the Permissions window, select "Full Control".

enter image description here

Once that's done you can go back to Docker and try creating a file.

docker run -it -v "$(pwd):/myapp" node:16 sh
cd myapp
touch b.txt

Upvotes: 2

xxxbence
xxxbence

Reputation: 2320

In my case on Win 10, I had to change the owner on the whole drive to my own user, than re-share the drive in docker with reset credentials. See the images below:

change the drive owner re-share the drive in docker

Upvotes: -1

RSeidelsohn
RSeidelsohn

Reputation: 1178

I struggled with this issue on Windows 10 for quite some time. The solution was a combination of suggestions I found on the internet - given that the directory you want to share is below your user directory:

  1. Create a new user in Windows - e.g. DockerHost (no email address needed, only user name and password)
  2. Grant reading rights to the first folder below your user directory, e.g. C:\Users\YourName\Development (right-click directory in the file manager, select the Security tab, make sure to have added the DockerHost user there and grant at least reading rights.
  3. Do the same for all the folders up to the folder you want to share
  4. In the Docker Desktop settings, go to Shared Drives, select your (probably) C-drive, reset credentials, then share again (check the checkbox and click on "Apply") and when prompted for a user name and password, enter the user name you created, e.g. DockerHost, along with the password.
  5. Now when running something like docker container run -p 80:80 -v C:\Users\YourName\Development\docker_examples:/usr/share/nginx/html --rm nginx, it should work

Upvotes: 1

JoeTortuga
JoeTortuga

Reputation: 376

this issue (which I somehow missed) Error mounting a config file into the container

answers the question.

I unshared C, reshared it and still had the problem. I clicked "reset credentials" and then reshared it (entering my password) and it worked.

Upvotes: 7

Related Questions