<p>Ideally dont run docker as superuser(root). You should create a user within dockerfile and chown the file system with that user. You can create a user and then add access to that user on the file system. In the below example there is appuser , with ownership to src</p>
<pre><code>FROM ubuntu:latest
RUN useradd -r -u 1001 -g appuser appuser
RUN chown -R appuser.appuser /src
USER appuser
CMD [&quot;appuser&quot;, &quot;/src/index.js&quot;] 
</code></pre>
<p>Its not recommended to run as root
You could also run as any user (Say root id = 0) if needed from externally</p>
<pre><code>docker run -d --user 0 ubuntu:latest
</code></pre>
<p>You should never relay on gid/uid  of the linux user outside the container.</p>

CC BY-SA 4.0
2020-11-07T07:32:33.503Z
Thank you for your answer. But I don't run the container with root. I have a user in my Docker file (application). But even with the chown, it mounts the files with 1001:1001 : http://i.imgur.com/AgzWEDG.png

And my `docker run -v ${PWD}:/app [...]` set bad user/group permissions : http://i.imgur.com/Dr0uFds.png

Any idea ?
Boris
CC BY-SA 4.0
2022-02-09T10:35:20.327Z
@Boris I ran into the same issue (on Windows and Docker Desktop). It seems that Docker mounts folders with 1001:1001 so you will need to have that user created with UID 1001 or `docker run -v $PWD:/app -u 1001:1001`. Nothing on the Internet explains why the folder is mounted with 1001:1001 ownership.
Silviu Burcea
CC BY-SA 4.0
2020-11-06T19:25:04.247Z
2020-11-06T19:25:04.247Z
Suresh Thomas
<p>Sounds like you are using a host volume. Docker doesn't perform any uid/gid mapping on the files mounted into the container, this is how bind mounts work in Linux. On Windows and Mac, Docker Desktop may do a convenience mapping to eliminate permission issues, but that's a feature of those platforms that doesn't exist in Linux. You'll either need to configure the container to work with the volume mount, make the image match the uid/gid on the host, or avoid host mounts.</p>
<p>For the first option, in development I often start containers as root, have them adjust the container user to match the volume owner, and then use gosu to drop from root to the container user to run the app. I implement this and include an example in my <a href="https://github.com/sudo-bmitch/docker-base" rel="nofollow noreferrer">base image repo</a>. See the <code>bin/fix-perms</code> script that adjusts the container uid/gid, <code>bin/entrypointd.sh</code> that looks for the RUN_AS variable to call gosu, and <code>examples/nginx/entrypoint.d/10-fix-perms.sh</code> that runs the fix-perms script.</p>

CC BY-SA 4.0
2020-12-06T21:03:54.610Z
2020-12-06T21:03:54.610Z
BMitch
<p>I have a Docker image that runs a PHP application. Everything works fine on my machine and the ones of my colleagues.</p>
<p>However, some colleagues got a new computer that runs on Ubuntu 20.04 and by default the user on these computers have the user id 1001. If I run the <code>id</code> command on these computers I get 1001 for the user id and group id. So, when they start the container, the files are chown with 1001:1001 and the code cannot be executed and no files can be written in the document root of the project.</p>
<p>How to fix this issue?</p>

<docker><permissions>
Docker mounts files as uid 1001
Boris
# Docker mounts files as uid 1001

(Asked by: username_0 on 2020-11-05)

I have a Docker image that runs a PHP application. Everything works fine on my machine and the ones of my colleagues.

However, some colleagues got a new computer that runs on Ubuntu 20.04 and by default the user on these computers have the user id 1001. If I run the `id` command on these computers I get 1001 for the user id and group id. So, when they start the container, the files are chown with 1001:1001 and the code cannot be executed and no files can be written in the document root of the project.

How to fix this issue?

**Tags:** docker, permissions


---

## 2 answers

### Answer by username_3 on 2020-12-06. Score: 3 | Accepted answer

Sounds like you are using a host volume. Docker doesn't perform any uid/gid mapping on the files mounted into the container, this is how bind mounts work in Linux. On Windows and Mac, Docker Desktop may do a convenience mapping to eliminate permission issues, but that's a feature of those platforms that doesn't exist in Linux. You'll either need to configure the container to work with the volume mount, make the image match the uid/gid on the host, or avoid host mounts.

For the first option, in development I often start containers as root, have them adjust the container user to match the volume owner, and then use gosu to drop from root to the container user to run the app. I implement this and include an example in my [base image repo](https://github.com/sudo-bmitch/docker-base). See the `bin/fix-perms` script that adjusts the container uid/gid, `bin/entrypointd.sh` that looks for the RUN\_AS variable to call gosu, and `examples/nginx/entrypoint.d/10-fix-perms.sh` that runs the fix-perms script.


---

### Answer by username_1 on 2020-11-06. Score: 1

Ideally dont run docker as superuser(root). You should create a user within dockerfile and chown the file system with that user. You can create a user and then add access to that user on the file system. In the below example there is appuser , with ownership to src
FROM ubuntu:latest
RUN useradd -r -u 1001 -g appuser appuser
RUN chown -R appuser.appuser /src
USER appuser
CMD ["appuser", "/src/index.js"] 

Its not recommended to run as root
You could also run as any user (Say root id = 0) if needed from externally
docker run -d --user 0 ubuntu:latest

You should never relay on gid/uid  of the linux user outside the container.

> **Comments:**
> **username_0**: Thank you for your answer. But I don't run the container with root. I have a user in my Docker file (application). But even with the chown, it mounts the files with 1001:1001 : http://i.imgur.com/AgzWEDG.png  And my `docker run -v ${PWD}:/app [...]` set bad user/group permissions : http://i.imgur.com/Dr0uFds.png  Any idea ?  
> **username_2**: @username_0 I ran into the same issue (on Windows and Docker Desktop). It seems that Docker mounts folders with 1001:1001 so you will need to have that user created with UID 1001 or `docker run -v $PWD:/app -u 1001:1001`. Nothing on the Internet explains why the folder is mounted with 1001:1001 ownership.  

---

