Skip to content

Commit 3aae08a

Browse files
committed
Allow arbitrary --user values
1 parent 4128e2c commit 3aae08a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Dockerfile

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# https://github.com/nodejs/LTS
33
FROM node:4-slim
44

5+
RUN groupadd user && useradd --create-home --home-dir /home/user -g user user
6+
57
# grab gosu for easy step-down from root
68
ENV GOSU_VERSION 1.7
79
RUN set -x \
@@ -36,7 +38,12 @@ RUN buildDeps=' \
3638
&& rm -rf /tmp/npm*
3739

3840
ENV GHOST_CONTENT /var/lib/ghost
39-
RUN mkdir -p "$GHOST_CONTENT"
41+
RUN mkdir -p "$GHOST_CONTENT" \
42+
&& chown -R user:user "$GHOST_CONTENT" \
43+
# Ghost expects "config.js" to be in $GHOST_SOURCE, but it's more useful for
44+
# image users to manage that as part of their $GHOST_CONTENT volume, so we
45+
# symlink.
46+
&& ln -s "$GHOST_CONTENT/config.js" "$GHOST_SOURCE/config.js"
4047
VOLUME $GHOST_CONTENT
4148

4249
COPY docker-entrypoint.sh /entrypoint.sh

docker-entrypoint.sh

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#!/bin/bash
22
set -e
33

4+
# allow the container to be started with `--user`
5+
if [[ "$*" == npm*start* ]] && [ "$(id -u)" = '0' ]; then
6+
chown -R user "$GHOST_CONTENT"
7+
exec gosu user "$BASH_SOURCE" "$@"
8+
fi
9+
410
if [[ "$*" == npm*start* ]]; then
511
baseDir="$GHOST_SOURCE/content"
612
for dir in "$baseDir"/*/ "$baseDir"/themes/*/; do
@@ -17,17 +23,6 @@ if [[ "$*" == npm*start* ]]; then
1723
s!path.join\(__dirname, (.)/content!path.join(process.env.GHOST_CONTENT, \1!g;
1824
' "$GHOST_SOURCE/config.example.js" > "$GHOST_CONTENT/config.js"
1925
fi
20-
21-
ln -sf "$GHOST_CONTENT/config.js" "$GHOST_SOURCE/config.js"
22-
23-
PUID=${PUID:-1001}
24-
PGID=${PGID:-1001}
25-
groupadd -o -g "$PGID" user
26-
useradd --create-home --home-dir /home/user -g user -o -u "$PUID" user
27-
28-
chown -R user:user "$GHOST_CONTENT"
29-
30-
set -- gosu user "$@"
3126
fi
3227

3328
exec "$@"

0 commit comments

Comments
 (0)