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 FROM debian:stretch
ENV TERRARIA_VERISON=1353 \ 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 \ RUN set -ex \
&& apt-get update \ && apt-get update \
@ -12,22 +16,22 @@ RUN set -ex \
unzip \ unzip \
&& useradd -m gameserver \ && useradd -m gameserver \
&& mkdir /data && chown gameserver: /data \ && 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 \ && 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 \ && curl -sSfLo /usr/local/bin/gosu https://github.com/tianon/gosu/releases/download/${GOSU_VERSION}/gosu-amd64 \
&& rm -rf /var/cache/apk/* && 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 \
USER gameserver /usr/local/bin/dumb-init \
ENV HOME /home/gameserver /usr/local/bin/gosu \
ENV SERVER $HOME/terraria
RUN set -ex \
&& mkdir -p ${SERVER} \ && mkdir -p ${SERVER} \
&& curl -sSLo /tmp/terraria.zip http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip && unzip -d ${SERVER} /tmp/terraria.zip \ && curl -sSfLo /tmp/terraria.zip "http://terraria.org/server/terraria-server-${TERRARIA_VERISON}.zip" \
&& ln -s ${SERVER}/terraria-server-* ${SERVER}/server \ && unzip -d ${SERVER} /tmp/terraria.zip \
&& rm /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 config.ini ${SERVER}/config.ini.default
COPY start.sh ${SERVER}/start.sh COPY start.sh ${SERVER}/start.sh
COPY terraria_cmd.sh /usr/local/bin/terraria_cmd
VOLUME /data VOLUME /data
EXPOSE 7777/udp 7777 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: You can simply run the image with the default settings:
``` ```console
docker run -d -p 7777:7777 luzifer/terraria $ 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: If you want the world to persist you can mount a volume into the container:
``` ```console
docker run -d -p 7777:7777 -v ~/terraria:/data luzifer/terraria $ 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). #Creates a new world if none is found. World size is specified by: 1(small), 2(medium), and 3(large).
#autocreate=1 #autocreate=1
autocreate=3 autocreate=1
#Sets the world seed when using autocreate #Sets the world seed when using autocreate
#seed=AwesomeSeed #seed=AwesomeSeed

View file

@ -1,8 +1,8 @@
#!/bin/bash #!/usr/local/bin/dumb-init /bin/bash
set -euxo pipefail set -euxo pipefail
if ! [ -e /data/config.ini ]; then if ! [ -e /data/config.ini ]; then
cp ${SERVER}/config.ini.default /data/config.ini cp ${SERVER}/config.ini.default /data/config.ini
fi fi
SERVER_BINARY=$(find /home/gameserver -name 'TerrariaServer.bin.x86_64') 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 # FIX: The ZIP archive does not have correct permissions
chmod +x "${SERVER_BINARY}" 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