3. Sort and push your Docker file
1: Create your Docker file
Section titled “1: Create 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 containerRUN useradd -m gameuser
# set permissionsRUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
# set your game binary as the entrypointENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]
# add port number(s) needed for your gameEXPOSE 1024/udpEXPOSE 7777/udpYour 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:
Bridge networking Docker file:
Section titled “Bridge networking Docker file:”FROM ubuntu:focal
#copy server filesCOPY . /home/MyGame/
RUN useradd -m gameuser
# set permissionsRUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
ENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]
EXPOSE 1024/udpEXPOSE 7777/udpHost networking Dockerfile:
Section titled “Host networking Dockerfile:”FROM ubuntu:focal
#copy server filesCOPY . /home/MyGame/
RUN useradd -m gameuser
# set permissionsRUN chmod 777 /home/MyGame/GameServer.sh
USER gameuser
ENTRYPOINT ["/home/MyGame/GameServer.sh", "-log"]Entrypoint:
Section titled “Entrypoint:”#!/bin/shUE4_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=10242: 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.