Skip to content

3. Sort and push your Docker file

Someone in your team will have to code your Docker file. This should only take about ten minutes as it’s fairly straightforward. But you’ll need to test this with your game binary, which can take some time to get right.

Your **Dockerfile **should contain either ENTRYPOINT or something similar that the user you’ve created will launch. Make sure everything is correct, otherwise it’ll cause issues when starting the container.

Here’s a code block you can use as a template. It’s a basic Dockerfile that will work for most situations.

FROM ubuntu:20.04
# copy your server files here
# for example:
COPY . /home/MyGame/
# add user to run the container
RUN useradd -m gameuser
# set permissions
RUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
# set your game binary as the entrypoint
ENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]
# add port number(s) needed for your game
EXPOSE 1024/udp
EXPOSE 7777/udp

Your networking method might affect the file

Section titled “Your networking method might affect the file”

Depending on the networking method you pick in the next step, you might need to change your Dockerfile. For now, here are a couple of examples:

FROM ubuntu:focal
#copy server files
COPY . /home/MyGame/
RUN useradd -m gameuser
# set permissions
RUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
ENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]
EXPOSE 1024/udp
EXPOSE 7777/udp
FROM ubuntu:focal
#copy server files
COPY . /home/MyGame/
RUN useradd -m gameuser
# set permissions
RUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
ENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]
#!/bin/sh
UE4_TRUE_SCRIPT_NAME=$(echo \"$0\" | xargs readlink -f)
UE4_PROJECT_ROOT=$(dirname "$UE4_TRUE_SCRIPT_NAME")
chmod +x "$UE4_PROJECT_ROOT/MyGame/Binaries/Linux/GameServer"
"$UE4_PROJECT_ROOT/MyGame/Binaries/Linux/GameServer" MyGame $@ -port=7777 -GameServerQueryPort=1024

2: Push your new Docker image to Dockerhub

Section titled “2: Push your new Docker image to Dockerhub”

Now that everything is packaged together as an image, push it to Dockerhub. This is a good time to test if everything works by using our sandbox environment.