Skip to content

Commit d55afb9

Browse files
committed
Overhaul rootless implementation (#364, #389, #393)
1 parent b856b7f commit d55afb9

File tree

3 files changed

+70
-14
lines changed

3 files changed

+70
-14
lines changed

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM steamcmd/steamcmd:ubuntu-22
22

3+
ARG GID=1000
4+
ARG UID=1000
5+
36
ENV AUTOSAVENUM="5" \
47
DEBIAN_FRONTEND="noninteractive" \
58
DEBUG="false" \
@@ -25,7 +28,8 @@ RUN set -x \
2528
&& apt-get update \
2629
&& apt-get install -y gosu xdg-user-dirs curl jq tzdata --no-install-recommends \
2730
&& rm -rf /var/lib/apt/lists/* \
28-
&& useradd -ms /bin/bash steam \
31+
&& groupadd -g ${GID} steam \
32+
&& useradd -u ${UID} -g ${GID} -ms /bin/bash steam \
2933
&& gosu nobody true
3034

3135
RUN mkdir -p /config \

README.md

Lines changed: 52 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,20 +245,65 @@ really get the best out of multiplayer:
245245
- Right-click each of the 3 config files (Engine.ini, Game.ini, Scalability.ini)
246246
- Go to Properties > tick Read-only under the attributes
247247

248-
## Rootless
248+
## Running as Non-Root User
249249

250-
If you'd prefer to run the container as a non-root user, just pass your preferred user to the container using Docker's
251-
own user implementation (e.g. `--user 1000:1000`). Do note that the container will print a warning for this, and this
252-
may cause permissions-related issues.
250+
By default, the container runs with root privileges but executes Satisfactory under `1000:1000`. If your host's user and
251+
group IDs are `1000:1000`, you can run the entire container as non-root using Docker's `--user` directive. For different
252+
user/group IDs, you'll need to clone and rebuild the image with your specific UID/GID:
253+
254+
### Building Non-Root Image
255+
256+
1. Clone the repository:
257+
258+
```shell
259+
git clone https://github.com/wolveix/satisfactory-server.git
260+
```
261+
262+
2. Create a docker-compose.yml file with your desired UID/GID as build args (note that the `PUID` and `PGID` environment
263+
variables will no longer be needed):
264+
265+
```yaml
266+
services:
267+
satisfactory-server:
268+
container_name: 'satisfactory-server'
269+
hostname: 'satisfactory-server'
270+
build:
271+
context: .
272+
args:
273+
UID: 1001 # Your desired UID
274+
GID: 1001 # Your desired GID
275+
user: "1001:1001" # Must match UID:GID above
276+
ports:
277+
- '7777:7777/udp'
278+
- '7777:7777/tcp'
279+
volumes:
280+
- './satisfactory-server:/config'
281+
environment:
282+
- MAXPLAYERS=4
283+
- STEAMBETA=false
284+
restart: unless-stopped
285+
deploy:
286+
resources:
287+
limits:
288+
memory: 8G
289+
reservations:
290+
memory: 4G
291+
```
292+
293+
3. Build and run the container:
294+
295+
```shell
296+
docker compose up -d
297+
```
253298

254299
## Known Issues
255300

256-
- The container is run as `root`. This is pretty common for Docker images, but is bad practice for security reasons.
257-
This change was made to address [permissions issues](https://github.com/wolveix/satisfactory-server/issues/44)
301+
- The container is run as `root` by default. You can provide your own user and group using Docker's `--user` directive;
302+
however, if your proposed user and group aren't `1000:1000`, you'll need to rebuild the image (as outlined above).
258303
- The server log will show various errors; most of which can be safely ignored. As long as the container continues to
259304
run and your log looks similar to the example log, the server should be functioning just
260305
fine: [example log](https://github.com/wolveix/satisfactory-server/blob/main/server.log)
261306

262307
## Star History
263308

264-
[![Star History Chart](https://api.star-history.com/svg?repos=wolveix/satisfactory-server&type=Date)](https://star-history.com/#wolveix/satisfactory-server&Date)
309+
[![Star History Chart](https://api.star-history.com/svg?repos=wolveix/satisfactory-server&type=Date)](https://star-history.com/#wolveix/satisfactory-server&Date)

init.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,17 @@ set -e
44

55
printf "===== Satisfactory Server %s =====\\nhttps://github.com/wolveix/satisfactory-server\\n\\n" "$VERSION"
66

7-
CURRENTUID=$(id -u)
8-
HOME="/home/steam"
97
MSGERROR="\033[0;31mERROR:\033[0m"
108
MSGWARNING="\033[0;33mWARNING:\033[0m"
119
NUMCHECK='^[0-9]+$'
1210
RAMAVAILABLE=$(awk '/MemAvailable/ {printf( "%d\n", $2 / 1024000 )}' /proc/meminfo)
13-
USER="steam"
11+
12+
export CURRENTGID=$(id -g)
13+
export CURRENTUID=$(id -u)
14+
export HOME="/home/steam"
15+
export STEAMGID=$(id -g steam)
16+
export STEAMUID=$(id -u steam)
17+
export USER="steam"
1418

1519
if [[ "${DEBUG,,}" == "true" ]]; then
1620
printf "Debugging enabled (the container will exit after printing the debug info)\\n\\nPrinting environment variables:\\n"
@@ -53,10 +57,13 @@ if [[ "${LOG,,}" != "true" ]]; then
5357
fi
5458
fi
5559

56-
# check if the user and group IDs have been set. If so, reset HOME to the upstream default
5760
if [[ "$CURRENTUID" -ne "0" ]]; then
58-
HOME="/root"
59-
printf "${MSGWARNING} Current user (%s) is not root (0).\\nNo permissions will be adjusted as we're running within a rootless environment.\\n" "$CURRENTUID"
61+
if [[ "$STEAMUID" -ne "$CURRENTUID" ]] || [[ "$STEAMGID" -ne $(id -g) ]]; then
62+
printf "${MSGERROR} Current user (%s:%s) is not root (0:0), and doesn't match the steam user/group (%s:%s).\\nTo run the container as non-root with a UID/GID that differs from the steam user, you must build the Docker image with the UID and GID build arguments set.\\n" "$CURRENTUID" "$CURRENTGID" "$STEAMUID" "$STEAMGID"
63+
exit 1
64+
fi
65+
66+
printf "${MSGWARNING} Running as non-root user (%s:%s).\\n" "$CURRENTUID" "$CURRENTGID"
6067
fi
6168

6269
if ! [[ "$PGID" =~ $NUMCHECK ]] ; then

0 commit comments

Comments
 (0)