Use Cases:

Dedicated Servers

Run Unreal Engine dedicated servers for multiplayer experiences.

Here's what you'll need:

Contents

Overview

An Unreal Engine dedicated server is a headless build of an Unreal project designed solely for handling game logic and network replication for multiplayer experiences. Client builds of the project connect to a dedicated server in order to share a common gameplay session.

Key considerations

Implementation guidelines

Creating a Linux container image

Copying pre-packaged files into an image

If you have already packaged a dedicated server for Linux on the host system then you can simply copy these files into a distroless base image like so:

# Copy the pre-packaged files into a minimal container image
FROM gcr.io/distroless/cc-debian10:nonroot
COPY --chown=nonroot:nonroot ./LinuxServer /home/nonroot/server

# Expose the port that the dedicated server listens on
EXPOSE 7777/udp

# Set the dedicated server as the container's entrypoint
# (Replace "MyProject" with the name of your project)
ENTRYPOINT ["/home/nonroot/server/MyProject/Binaries/Linux/MyProjectServer", "MyProject"]

Note that the minimal nature of the distroless image means it does not include a shell like Bash to interpret shell scripts, and so the default startup script for the dedicated server (e.g. MyProjectServer.sh) cannot be used as the container entrypoint. Instead, the container entrypoint needs to be configured to directly run the underlying executable for the dedicated server, including the command-line flags that would normally be passed to it by the startup script.

Performing a multi-stage build

If you would like to build the dedicated server inside a container then you can use a multi-stage build to perform the build process in an Unreal Engine development image and then copy the results to a distroless base image like so:

# This example uses the official development image for Unreal Engine 4.27, but any development image will work
FROM ghcr.io/epicgames/unreal-engine:dev-4.27 as builder

# Copy the source code for the project into the container
COPY --chown=ue4:ue4 . /tmp/project

# Build and package the dedicated server for the project
# (Replace "MyProject" with the name of your project)
RUN /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun \
	-Server -NoClient -ServerConfig=Development \
	-Project=/tmp/project/MyProject.uproject \
	-UTF8Output -NoDebugInfo -AllMaps -NoP4 -Build -Cook -Stage -Pak -Package -Archive \
	-ArchiveDirectory=/tmp/project/Packaged \
	-Platform=Linux

# Copy the packaged files into a minimal container image
FROM gcr.io/distroless/cc-debian10:nonroot
COPY --from=builder --chown=nonroot:nonroot /tmp/project/Packaged/LinuxServer /home/nonroot/project

# Expose the port that the dedicated server listens on
EXPOSE 7777/udp

# Set the dedicated server as the container's entrypoint
# (Replace "MyProject" with the name of your project)
ENTRYPOINT ["/home/nonroot/project/MyProject/Binaries/Linux/MyProjectServer", "MyProject"]

Windows container compatibility

Setting the application subsystem

As discussed in the blog post Offscreen rendering in Windows containers, Unreal Engine applications built for Windows are designed to act as graphical applications rather than command-line applications, which prevents them from running correctly inside containers. This also applies to dedicated server targets and must be fixed in the same manner as non-server targets, by instructing UnrealBuildTool to build an additional executable as a command-line application through the bBuildAdditionalConsoleApp configuration value in the .Target.cs file:

using UnrealBuildTool;
using System.Collections.Generic;

// Note that this is the dedicated server target file for the project (e.g. `MyProjectServer.Target.cs`),
// NOT the Editor target file for the project (e.g. `MyProjectEditor.Target.cs`)
// or the standalone game target file for the project (e.g. `MyProject.Target.cs`)
public class MyProjectServerTarget : TargetRules
{
	public MyProjectServerTarget(TargetInfo Target) : base(Target)
	{
		Type = TargetType.Server;
		DefaultBuildSettings = BuildSettingsVersion.V2;
		ExtraModuleNames.AddRange( new string[] { "MyProject" } );
		
		// This instructs UBT to build an additional executable with the CONSOLE subsystem
		bBuildAdditionalConsoleApp = true;
	}
}

When you package the dedicated server for your project, an additional executable with the suffix -Cmd will be produced alongside the regular binary. For example, if your project is called “MyProject” and you packaged it in the Development configuration then you will see two executables named as follows:

Required dependencies

Despite not performing any rendering, dedicated servers still require the following Microsoft Media Foundation DLL files as of Unreal Engine 4.27:

These DLL files are not present in the Windows Server Core base image and will need to be copied from the Windows base image (prior to Windows Server 2022) or the Windows Server base image (for Windows Server 2022 and newer.)