Skip to content

Commit

Permalink
Run as non-root user in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
rebkwok committed Dec 12, 2023
1 parent a4321bf commit 2de02e8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ ARG GITREF=unknown
LABEL org.opencontainers.image.revision=$GITREF


ARG USERID=10001
ARG GROUPID=10001
USER ${USERID}:${GROUPID}

##################################################
#
# Dev image
Expand All @@ -167,3 +171,8 @@ RUN --mount=type=cache,target=/root/.cache \

# Override ENTRYPOINT rather than CMD so we can pass arbitrary commands to the entrypoint script
ENTRYPOINT ["/app/docker/entrypoints/dev.sh"]

# Run as non root user. Required when building image.
ARG USERID
ARG GROUPID
USER ${USERID}:${GROUPID}
4 changes: 4 additions & 0 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ services:
build:
# the dev stage in the Dockerfile
target: opencodelists-dev
args:
# user developer uid:gid in dev
- USERID=${DEV_USERID:-1000}
- GROUPID=${DEV_GROUPID:-1000}
# paths relative to docker-compose.yaml file
volumes:
- ..:/app
Expand Down
4 changes: 4 additions & 0 deletions docker/justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export COMPOSE_DOCKER_CLI_BUILD := "1"

export BIN := "/opt/venv/bin"

export DEV_USERID := `id -u`
export DEV_GROUPID := `id -g`


build env="dev":
#!/usr/bin/env bash
Expand Down

0 comments on commit 2de02e8

Please sign in to comment.