Answers: <p>In your Dockerfile:</p>
  <pre><code>ARG UID=1000
  ARG GID=1000
  
  RUN usermod -u $UID node &amp;&amp; groupmod -g $GID node
  </code></pre>
  <p>Then using <code>docker build</code>:</p>
  <pre><code>docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) .
  </code></pre>
  <p>The <code>ARG</code> lines provide defaults. If you leave off the <code>--build-arg</code> flags, they will be used. If you do use the <code>--build-arg</code> flags values those will be used instead.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-25T07:39:19.510Z
Answers: Thx, both answers are useful. I will add args with defaults to Dockerfile, then override them in compose file for local dev. Cheers!
Answers: U2ros
Answers: CC BY-SA 4.0
Answers: 2020-09-24T00:46:35.223Z
Answers: 2020-09-24T00:46:35.223Z
Answers: bradym
Answers: <p>The Compose syntax <a href="https://docs.docker.com/compose/compose-file/#domainname-hostname-ipc-mac_address-privileged-read_only-shm_size-stdin_open-tty-user-working_dir" rel="nofollow noreferrer">allows you to specify</a> <code>user: &lt;uid&gt;:&lt;gid&gt;</code> in the service's configuration block.</p>
  <p>For example:</p>
  <pre><code>version: &quot;3&quot;
  services:
    node-service:
      image: node
      user: 1001:1001
  </code></pre>
  <p>This will run the container as UID 1001 and GID 1001.</p>
  
Answers: CC BY-SA 4.0
Answers: 2020-09-23T15:25:13.213Z
Answers: 2020-09-23T15:25:13.213Z
Answers: swysocki
Body: <p>I have an interesting problem with node, docker-compose and local development using bind mounts.</p>
  <p>I have a bind mount volume, called www-public, owned by my host node user (I created a node user and chowned the dir to node:node). The container (official node) is set up so it also run as node user. At some point in my node app, i need to write to this folder and i get the permission error. This seems strange at first, but it makes sense, because i figured then, that my host nodeuser has an uid of 1001 while my container node user has an id of 1000. If i just add this line to my Dockerfile:</p>
  <pre><code>RUN usermod -u 1001 node &amp;&amp; groupmod -g 1001 node
  </code></pre>
  <p>The permission problem goes away.</p>
  <p>How do i fix this in a way, that I don't hard code the container node user id to match the node user id on the host like i did with the upper RUN command.</p>
  
Tags: <docker><docker-compose><node.js><permissions>
Title: Dockerized node.js and bind mount permission problem
UserDisplayName: U2ros
ThreadText: # Dockerized node.js and bind mount permission problem
  
  (Asked by: username_0 on 2020-09-23)
  
  I have an interesting problem with node, docker-compose and local development using bind mounts.
  
  I have a bind mount volume, called www-public, owned by my host node user (I created a node user and chowned the dir to node:node). The container (official node) is set up so it also run as node user. At some point in my node app, i need to write to this folder and i get the permission error. This seems strange at first, but it makes sense, because i figured then, that my host nodeuser has an uid of 1001 while my container node user has an id of 1000. If i just add this line to my Dockerfile:
  
  ```
  RUN usermod -u 1001 node && groupmod -g 1001 node
  
  ```
  
  The permission problem goes away.
  
  How do i fix this in a way, that I don't hard code the container node user id to match the node user id on the host like i did with the upper RUN command.
  
  **Tags:** docker, docker-compose, node.js, permissions
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2020-09-24. Score: 1 | Accepted answer
  
  In your Dockerfile:
  
  ```
  ARG UID=1000
  ARG GID=1000
  
  RUN usermod -u $UID node && groupmod -g $GID node
  
  ```
  
  Then using `docker build`:
  
  ```
  docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) .
  
  ```
  
  The `ARG` lines provide defaults. If you leave off the `--build-arg` flags, they will be used. If you do use the `--build-arg` flags values those will be used instead.
  
  > **Comments:**
  > **username_0**: Thx, both answers are useful. I will add args with defaults to Dockerfile, then override them in compose file for local dev. Cheers!  
  
  ---
  
  ### Answer by username_2 on 2020-09-23. Score: 0
  
  The Compose syntax [allows you to specify](https://docs.docker.com/compose/compose-file/#domainname-hostname-ipc-mac_address-privileged-read_only-shm_size-stdin_open-tty-user-working_dir) `user: <uid>:<gid>` in the service's configuration block.
  
  For example:
  
  ```
  version: "3"
  services:
    node-service:
      image: node
      user: 1001:1001
  
  ```
  
  This will run the container as UID 1001 and GID 1001.
  
  
  ---
  
  