Skip to content

Commit e4c5846

Browse files
committed
Fix entrypoint.sh and add sane defaults
1 parent fabfb53 commit e4c5846

2 files changed

Lines changed: 31 additions & 11 deletions

File tree

python3/bin/entrypoint.sh

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
#!/usr/bin/env bash
2+
DEFAULT_UID=10000
3+
DEFAULT_GID=10000
4+
25
set -e
36

47
if [[ -v DEBUG ]]
@@ -23,10 +26,10 @@ create_user_and_group() {
2326
echo " Please recreate the container with the updated gid" >&2
2427
exit 1
2528
fi
26-
echo "Group '$groupname' already exists with correct GID $gid"
29+
echo "Group '$groupname' already exists with correct GID $gid" >&2
2730
else
2831
# Group doesn't exist, create it
29-
echo "Creating group '$groupname' with GID $gid"
32+
echo "Creating group '$groupname' with GID $gid" >&2
3033
groupadd -g "$gid" "$groupname"
3134
fi
3235
fi
@@ -51,14 +54,14 @@ create_user_and_group() {
5154
fi
5255
fi
5356

54-
echo "User '$username' already exists with correct UID $uid"
57+
echo "User '$username' already exists with correct UID $uid" >&2
5558
else
5659
# User doesn't exist, create it
5760
if [ -n "$gid" ]; then
58-
echo "Creating user '$username' with UID $uid and GID $gid"
61+
echo "Creating user '$username' with UID $uid and GID $gid" >&2
5962
useradd -M -u "$uid" -g "$gid" "$username"
6063
else
61-
echo "Creating user '$username' with UID $uid"
64+
echo "Creating user '$username' with UID $uid" >&2
6265
useradd -M -u "$uid" "$username"
6366
fi
6467
fi
@@ -82,12 +85,8 @@ then
8285
fi
8386

8487
# set up privilege dropping to user and group
85-
PRIVDROP=
86-
if [ -n "$RUNAS_UID" ]
87-
then
88-
PRIVDROP=$(create_user_and_group "$RUNAS_UID" "$RUNAS_GID")
89-
echo "Dropping privileges to $($PRIVDROP id -u):$($PRIVDROP id -g)"
90-
fi
88+
PRIVDROP=$(create_user_and_group "${RUNAS_UID:-$DEFAULT_UID}" "${RUNAS_GID:-$DEFAULT_GID}")
89+
echo "Dropping privileges to $($PRIVDROP id -u):$($PRIVDROP id -g)"
9190

9291
# run custom scripts before dropping privileges
9392
echo "Running custom scripts in /container-init as root"

python3/test.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/bash
2+
echo "Build image"
3+
docker build -t python3:test . --no-cache
4+
5+
echo
6+
echo "Remove old container"
7+
docker rm python3
8+
9+
# With RUNAS_UID and RUNAS_GID
10+
echo
11+
echo "Run image with env"
12+
docker run --name python3 --env RUNAS_UID=10001 --env RUNAS_GID=10001 python3:test
13+
14+
# Without RUNAS_UID and RUNAS_GID
15+
# echo
16+
# echo "Run without env"
17+
# docker run --name python3 python3:mve
18+
19+
echo
20+
echo "Start container"
21+
docker start -i python3

0 commit comments

Comments
 (0)