@@ -81,14 +81,16 @@ RUN set -ex && \
8181
8282FROM docker.io/python:${PYTHON_VERSION}-slim AS app_runtime
8383ARG PYTHON_VERSION=3.12
84+ ARG APP_UID=999
8485
8586# Add the application virtualenv to search path.
8687ENV PATH=/app/bin:$PATH
8788
88- # Don't run your app as root.
89+ # We will run the app as a user 'app' with a stable uid that is
90+ # configurable via an ARG.
8991RUN set -ex && \
90- groupadd -r app && \
91- useradd -r -d /app -g app -N app
92+ groupadd -r -g ${APP_UID} app && \
93+ useradd -r -d /app -g app -u ${APP_UID} -N app
9294
9395# See <https://hynek.me/articles/docker-signals/>.
9496STOPSIGNAL SIGINT
@@ -100,7 +102,7 @@ apt-get update -qy && \
100102apt-get install -qyy \
101103 -o APT::Install-Recommends=false \
102104 -o APT::Install-Suggests=false \
103- curl && \
105+ curl gosu && \
104106apt-get clean && \
105107rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
106108
@@ -129,4 +131,13 @@ python -Ic 'import tiled'
129131
130132EXPOSE 8000
131133
134+ # Following the example of PG, Redis, and other services that write to a
135+ # storage volume, run the entrypoint as root. As root, ensure that the
136+ # /storage volume is writable by the app user. Then use gosu to switch to
137+ # the app user.
138+ USER root
139+ COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
140+ RUN chmod +x /usr/local/bin/docker-entrypoint.sh
141+ ENTRYPOINT ["docker-entrypoint.sh" ]
142+
132143CMD ["tiled" , "serve" , "config" , "--host" , "0.0.0.0" , "--port" , "8000" , "--scalable" ]
0 commit comments