Improve image, add command wrapper

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2018-06-08 12:34:37 +02:00
parent 9ec74b9601
commit 1c5ee42f5c
Signed by: luzifer
GPG Key ID: DC2729FDD34BE99E
5 changed files with 41 additions and 21 deletions

View File

@ -1,7 +1,11 @@
FROM debian:stretch
ENV TERRARIA_VERISON=1353 \
DUMB_INIT_VERSION=1.2.1
DUMB_INIT_VERSION=1.2.1 \
GOSU_VERSION=1.10 \
TERRARIA_DOCKER_VERSION=v0.1.0 \
HOME=/home/gameserver \
SERVER=/home/gameserver/terraria
RUN set -ex \
&& apt-get update \
@ -12,22 +16,22 @@ RUN set -ex \
unzip \
&& useradd -m gameserver \
&& mkdir /data && chown gameserver: /data \
&& curl -sSfLo /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 \
&& chmod +x /usr/local/bin/dumb-init \
&& rm -rf /var/cache/apk/*
USER gameserver
ENV HOME /home/gameserver
ENV SERVER $HOME/terraria
RUN set -ex \
&& curl -sSfLo /usr/local/bin/dumb-init "https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64" \
&& curl -sSfLo /usr/local/bin/gosu https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64 \
&& curl -sSfL "https://github.com/Luzifer/terraria-docker/releases/download/${TERRARIA_DOCKER_VERSION}/terraria-docker_linux_amd64.tar.gz" | tar -xz -C /usr/local/bin \
&& chmod +x \
/usr/local/bin/dumb-init \
/usr/local/bin/gosu \
&& mkdir -p ${SERVER} \
&& curl -sSLo /tmp/terraria.zip http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip && unzip -d ${SERVER} /tmp/terraria.zip \
&& ln -s ${SERVER}/terraria-server-* ${SERVER}/server \
&& rm /tmp/terraria.zip
&& curl -sSfLo /tmp/terraria.zip "http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip" \
&& unzip -d ${SERVER} /tmp/terraria.zip \
&& chown -R gameserver:gameserver ${SERVER} \
&& rm /tmp/terraria.zip \
&& rm -rf /var/lib/apt/lists/*
COPY config.ini ${SERVER}/config.ini.default
COPY start.sh ${SERVER}/start.sh
COPY terraria_cmd.sh /usr/local/bin/terraria_cmd
VOLUME /data
EXPOSE 7777/udp 7777

View File

@ -6,13 +6,20 @@ This image contains a [Terraria](http://terraria.org/) 1.3.5.3 server with autom
You can simply run the image with the default settings:
```
docker run -d -p 7777:7777 luzifer/terraria
```console
$ docker run -d --name=terraria -p 7777:7777 luzifer/terraria
```
If you want the world to persist you can mount a volume into the container:
```
docker run -d -p 7777:7777 -v ~/terraria:/data luzifer/terraria
```console
$ docker run -d --name=terraria -p 7777:7777 -v ~/terraria:/data luzifer/terraria
```
### Interacting with the server command line
In case you want to use the [console commands](https://terraria.gamepedia.com/Server#List_of_console_commands) on the Terraria server this image has a helper for you:
```console
$ docker exec terraria terraria_cmd save
```

View File

@ -30,7 +30,7 @@ world=/data/world/Terraria.wld
#Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large).
#autocreate=1
autocreate=3
autocreate=1
#Sets the world seed when using autocreate
#seed=AwesomeSeed

View File

@ -1,8 +1,8 @@
#!/bin/bash
#!/usr/local/bin/dumb-init /bin/bash
set -euxo pipefail
if ! [ -e /data/config.ini ]; then
cp ${SERVER}/config.ini.default /data/config.ini
cp ${SERVER}/config.ini.default /data/config.ini
fi
SERVER_BINARY=$(find /home/gameserver -name 'TerrariaServer.bin.x86_64')
@ -10,4 +10,9 @@ SERVER_BINARY=$(find /home/gameserver -name 'TerrariaServer.bin.x86_64')
# FIX: The ZIP archive does not have correct permissions
chmod +x "${SERVER_BINARY}"
exec tail -f /dev/null | "${SERVER_BINARY}" -config /data/config.ini "$@"
# Force data path to be writable
chown -R gameserver:gameserver /data
exec terraria-docker_linux_amd64 | /usr/local/bin/gosu \
gameserver \
${SERVER_BINARY} -config /data/config.ini "$@"

4
terraria_cmd.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/bash
set -euo pipefail
echo "$@" >/home/gameserver/terraria_cmd