Skip to content

Commit f20b0e7

Browse files
committed
Fix collisions with existing user and group ids
Do not add groups or users if ther gid or uid already exists in the base image. We also make useradd and the USER instruction depend on numeric ids since we can't guarantee that a group or user with name 'app' exists. The USER instruction now also includes the group id to ensure that any created files have the expected user and group ownership.
1 parent 785ede8 commit f20b0e7

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Dockerfile.unix

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ ARG RUBY_VERSION=3.3.4
22
FROM ruby:${RUBY_VERSION}
33
ARG USER_ID=1000
44
ARG GROUP_ID=1000
5-
RUN groupadd -g $GROUP_ID app && useradd -u $USER_ID -g app -m app
6-
USER app
5+
RUN (getent group $GROUP_ID > /dev/null || groupadd -g $GROUP_ID app) && \
6+
(getent passwd $USER_ID > /dev/null || useradd -u $USER_ID -g $GROUP_ID -m app)
7+
USER $USER_ID:$GROUP_ID
78
ARG RAILS_VERSION
89
# Install Rails based on the version specified but if not specified, install the latest version.
910
RUN if [ -z "$RAILS_VERSION" ] ; then gem install rails ; else gem install rails -v $RAILS_VERSION ; fi

0 commit comments

Comments
 (0)