D
D
doox9112021-01-26 10:46:23
Docker
doox911, 2021-01-26 10:46:23

Directory permissions not set in Docker Compose (Docker)?

Service (docker-compose.yml):

nodejs:
    build:
      context: configs/nodejs
      args:
        - UID=$UID
        - GID=$GID
    container_name: nodejs_container
    volumes:
      - ${APP_HOST}:${APP_CONTAINER_PATH}
    working_dir: ${APP_CONTAINER_FRONTEND_PATH}
    command: sh -c "ls -la && npm install && npm run build"

Dockerfile:

FROM node:lts-alpine
ARG UID
ARG GID
RUN npm install -g @vue/cli
USER $UID:$GID


But the file permissions are set incorrectly:
nodejs_container | total 728
nodejs_container | drwxrwxr-x    4 1001     xfs           4096 Jan 26 07:09 .
nodejs_container | drwxrwxr-x   15 1001     xfs           4096 Jan 26 06:06 ..
nodejs_container | -rw-rw-r--    1 1001     xfs             43 Jan 24 16:47 .browserslistrc
nodejs_container | -rw-rw-r--    1 1001     xfs            121 Jan 24 16:47 .editorconfig
nodejs_container | -rw-rw-r--    1 1001     xfs           3302 Jan 24 16:47 .eslintrc.js
nodejs_container | -rw-rw-r--    1 1001     xfs            283 Jan 24 16:47 .gitignore
nodejs_container | -rw-rw-r--    1 1001     xfs            427 Jan 24 16:47 README.md
nodejs_container | -rw-rw-r--    1 1001     xfs             76 Jan 24 16:47 babel.config.js
nodejs_container | -rw-rw-r--    1 1001     xfs             50 Jan 24 16:47 cypress.json
nodejs_container | -rw-rw-r--    1 1001     xfs            834 Jan 24 16:47 jest.config.js
nodejs_container | -rw-rw-r--    1 1001     xfs         680479 Jan 26 06:54 package-lock.json
nodejs_container | -rw-rw-r--    1 1001     xfs           2048 Jan 25 09:26 package.json
...


Before running docker, I set my environment variables: export UID = $(id -u) and export GID = $(id -g)

Why wasn't $UID:$GID set for directories and files from environment variables where docker was running composite?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wazza, 2021-01-28
@wazza

Because you must first add a user to the Dockerfile before using it:
RUN useradd -m ${USER} --uid=${UID} ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question