Skip to content

Commit 1d73232

Browse files
authored
Ensure uid, gid for postgres, redis and discourse stays consistent (#835)
When updating to `debian/base:bookworm` from `debian/base:bullseye`, we noticed that the uid of the `postgres` and `redis` user changed leading to permission issues when trying to access directories of mounted volumn which was previously created with the old uid. The change is because the `_apt` user is assigned a uid of `42` in Debian bookworm instead of `100` in Debian bullseye. As a result, the `postgres` user created by the `postgres` package is automatically assigned a uid of `100` in Debian bookworm instead of `101` in Debian bullseye. This commit updates the `slim.Dockefile` to manually add the `postgres` user and group assigning it a gid of `104` and uid of `101`. The `redis` user and group is assigned a uid of `103` and a gid of `106`. The `discourse` user and group is assigned a uid of `1000` and gid of `1000`.
1 parent 98c5337 commit 1d73232

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

image/base/slim.Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,16 @@ ENV PG_MAJOR=13 \
1717

1818
#LABEL maintainer="Sam Saffron \"https://twitter.com/samsaffron\""
1919

20-
RUN echo 2.0.`date +%Y%m%d` > /VERSION
20+
# Ensures that the gid and uid of the following users are consistent to avoid permission issues on directories in the
21+
# mounted volumes.
22+
RUN groupadd --gid 104 postgres &&\
23+
useradd --uid 101 --gid 104 --home /var/lib/postgresql --shell /bin/bash -c "PostgreSQL administrator,,," postgres &&\
24+
groupadd --gid 106 redis &&\
25+
useradd --uid 103 --gid 106 --home /var/lib/redis --shell /usr/sbin/nologin redis &&\
26+
groupadd --gid 1000 discourse &&\
27+
useradd --uid 1000 --gid 1000 -m --shell /bin/bash discourse
2128

29+
RUN echo 2.0.`date +%Y%m%d` > /VERSION
2230
RUN echo "deb http://deb.debian.org/debian ${DEBIAN_RELEASE}-backports main" > "/etc/apt/sources.list.d/${DEBIAN_RELEASE}-backports.list"
2331
RUN echo "debconf debconf/frontend select Teletype" | debconf-set-selections
2432
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -y install gnupg sudo curl fping
@@ -128,7 +136,6 @@ COPY etc/ /etc
128136
COPY sbin/ /sbin
129137

130138
# Discourse specific bits
131-
RUN useradd discourse -s /bin/bash -m -U &&\
132-
install -dm 0755 -o discourse -g discourse /var/www/discourse &&\
139+
RUN install -dm 0755 -o discourse -g discourse /var/www/discourse &&\
133140
sudo -u discourse git clone --filter=tree:0 https://github.com/discourse/discourse.git /var/www/discourse &&\
134141
gem install bundler --conservative -v $(awk '/BUNDLED WITH/ { getline; gsub(/ /,""); print $0 }' /var/www/discourse/Gemfile.lock)

0 commit comments

Comments
 (0)