Unofficial Docker container for a Terraria dedicated server. Vanilla and Modded.
100K+
Unofficial Docker container for a Terraria dedicated server. Supports vanilla and modded through tModLoader.
Note
This is not at all affiliated with Terraria or tModLoader. Please report issues here.
/opt/TerrariaServer/(Linux) or C:\TerrariaServer\(Windows).docker run -d --name terraria -p 7777:7777/tcp -v /opt/TerrariaServer/:/opt/terraria/config/ -e WORLD=myworld passivelemon/terraria-docker:terraria-latest/opt/TerrariaServer/(Linux) or C:\TerrariaServer\(Windows).ModPacks/ (See step 3 further down)docker run -d --name tmodloader1.4 -p 7777:7777/tcp -v /opt/TerrariaServer/:/opt/terraria/config/ -e MODPACK=<modpack name> -e WORLD=myworld passivelemon/terraria-docker:tmodloader-latestDepending on your host, find a suitable place to store your server files. Make sure it is empty, safe, and accessible. For example: On Windows, something like C:\TerrariaServer\ or a Linux equivalent like /opt/TerrariaServer/.
Note
For the sake of instruction, we will call this place ``. Any field wrapped in angle brackets is a field that needs to be substituted.
In <config_dir>, make one directory called Worlds, spelled exactly as show, and Modpacks if you are using tModLoader. This location is also where your serverconfig.txt will be stored if you want to use your own. Details on this are in step 4.
For every variable you want the server to use, add that variable to your docker run or compose with -e <variable>=<value>. If not set, they will use their default value.
By default, modded servers will not successfully run because they need a defined modpack.
Server configuration details on the Terraria Wiki.
| Variable | Options | Default | Details |
|---|---|---|---|
PUID | integer | 1000 | The UID to run the server with. |
PGID | integer | 1000 | The GID to run the server with. |
SERVERCONFIG | boolean | 0 | Enable to use a user defined config file. Otherwise it is autogenerated by the other environment variables. |
Caution
In order to prevent world corruption, autocreate does not have a default value for the vanilla Terraria Docker image (This doesn't affect tModLoader). If autocreate is set smaller than your current world size, you will likely experience some world corruption. Bug report [here](https://forums.terraria.org/index.php?threads/world-breaks-for-dedicated-servers-if-autocreate-config-option-is-set-incorrectly.146226/). This corruption is not permanent, only visual.
| Variable | Options | Default | Details |
|---|---|---|---|
AUTOCREATE | 1 2 3 | NA (Vanilla), 2 (TML) | The world size to autocreate if the worldname is not found. 1 for small, 2 for medium, 3 for large. |
BANLIST | string | banlist.txt | The file with the list of banned players. |
DIFFICULTY | 0 1 2 3 | 0 | The difficulty level to use with autocreate. 0 for normal, 1 for expert, 2 for master, 3 for journey. |
LANGUAGE | en-US de-DE it-IT fr-FR es-ES ru-RU zh-Hans pt-BR pl-PL | en-US | The language to use. |
MAXPLAYERS | integer | 8 | The maximum amount of players that can be on the server. |
MODPACK | string | NA | The modpack to start the server with. This only works with tModLoader. |
MOTD | string | NA | The message of the day. |
NPCSTREAM | integer 0-60 | 15 | Helps with entity skipping. |
PASSWORD | string | NA | The password required to join the server. |
PORT | integer | 7777 | The port to join the server. |
PRIORITY | integer 0-5 | 1 | Server process priority. Lower means higher priority. |
SECURE | boolean | 1 | Cheat protection. |
SEED | string | NA | The seed to use with autocreate. |
UPNP | boolean | 0 | Automatically forward ports with uPNP. |
WORLDNAME | string | World | The name of the world. This determines which world file to load. |
All Journey Mode variables have the same options. The default is 2.
0 for no-one, 1 for host only, 2 for everyone.
| Variable | Options | Default |
|---|---|---|
BIOMESPREAD_SETFROZEN | 0 1 2 | 2 |
GODMODE | ||
INCREASEPLACEMENTRANGE | ||
RAIN_SETFROZEN | ||
RAIN_SETSTRENGTH | ||
SETDIFFICULTY | ||
SETSPAWNRATE | ||
TIME_SETDAWN | ||
TIME_SETDUSK | ||
TIME_SETFROZEN | ||
TIME_SETMIDNIGHT | ||
TIME_SETNOON | ||
TIME_SETSPEED | ||
WIND_SETFROZEN | ||
WIND_SETSTRENGTH |
If you are not using tModLoader, then skip this step.
Ideally, you shouldn't include any client side only mods in the modpack folder for the server. Client side mods only affect the client (player) meaning they add zero new functionality to the game. Includes things like different textures, shaders, RPC, etc. Nothing bad should happen if you do but it's just best practice. Mods are included in the modpack folder so they do not need to be obtained manually.
<config_dir>/ModPacks/Make sure the modpack has an enabled.json with the mods you want or else the server will not start.
If you want to continue on an existing world, follow this step. Otherwise, just skip it. The server will generate a new world automatically.
If you provide a world file and correctly set the WORLDNAME variable, it will use the existing world.
If using tModLoader, make sure this world is always loaded with the same modpack or you may encounter world corruption.
C:\Users\<user>\Documents\My Games\Terraria\Worlds\ or the Linux equivalent, usually /home/<user>/.local/share/Terraria/Worlds/.C:\Users\<user>\Documents\My Games\Terraria\tModLoader\Worlds\ or the Linux equivalent, usually /home/<user>/.local/share/Terraria/tModLoader/Worlds/.<config_dir>/Worlds/. The world files look like .wld and, if using tModLoader, .twld.If you want to use your own server config, follow this step. Otherwise, just skip it. The server will generate a config automatically based on your provided environment variables.
The root of the terraria server files in the container is /opt/terraria/server/ and user items in <config_dir> are mounted at /opt/terraria/config/
SERVERCONFIG to 1.serverconfig.txt into <config_dir>.Server configuration details on the Terraria Wiki.
| Tag | Details |
|---|---|
latest | Same as terraria-latest. |
terraria-latest | Latest official Terraria release. |
terraria-<version> | Specific version of Terraria. |
tmodloader-latest | Latest tModLoader release (stable). |
tmodloader-latest-pre | Latest tModLoader pre-release (unstable). |
tmodloader-<year> | Latest tModLoader year release (stable). |
tmodloader-<year>-pre | Latest tModLoader year pre-release (unstable). |
tmodloader-<version> | Specific version of tModLoader. |
Though stable are likely fine, it is recommended to pin the server to a specific version to avoid potential save corruption.
Terraria versions at releases.
tModLoader versions at tModLoader (Do not include the v prefix).
docker run -d --name <container name> -p 7777:7777 -v <config_dir>:/opt/terraria/config/ passivelemon/terraria-docker:terraria-latest
services:
terraria-docker:
image: passivelemon/terraria-docker:terraria-latest
container_name: terraria-docker
ports:
- 7777:7777
volumes:
- <config_dir>:/opt/terraria/config/
| Operator | Need | Details |
|---|---|---|
-d | Yes | Will run the container in the background. |
--name <container name> | No | Sets the name of the container to the following string. You can change this to whatever you want. |
-p 7777:7777 | Yes | The default port used by the server. This translates from your host 7777 into the container 7777. If you use a different port for your server in your serverconfig, change this. |
-v <config_dir>:/opt/terraria/config | Yes | Sets the directory that holds the configs like your worlds and serverconfig.txt. This should be the place you chose at the beginning. |
passivelemon/terraria-docker:terraria-latest | Yes | The Docker image. By default, it is the latest version. |
docker run -d --name terraria -p 7777:7777/tcp -v /opt/terrariaServer/:/opt/terraria/config/ -e WORLD=myworld passivelemon/terraria-docker:terraria-latest
services:
terraria-docker:
image: passivelemon/terraria-docker:terraria-latest
container_name: terraria-docker
ports:
- 7777:7777
volumes:
- /opt/terrariaServer/:/opt/terraria/config/
environment:
WORLDNAME: "myworld"
If you have a service that depends on the health state of the container, you can add a healthcheck as such:
services:
terraria-docker:
# ...
healthcheck:
test: "nc -vz 127.0.0.1 7777 || exit 1" # Change 7777 to your internal server port if needed
interval: 30s
timeout: 5s
start_period: 10s
retries: 3
Note that this can inhibit server hibernation when no players are present.
Your config directory should look something like:
<config_dir>\ # This gets mounted to /opt/terraria/config/ in the container.
Logs\ # This is optional. Make sure to mount it if you want it to be populated.
Worlds\ # Default folder needed by the server.
ModPacks\ # Modpack directory if using tModLoader.
serverconfig.txt # config file needed by the server (Only if you want to use your own).
Theres a few ways around this:
Playing completely over LAN. If your server and players are on the same network, then you can use the local IP of the server host.
Playing over a VPN like Tailscale, ZeroTier, or other. You can then follow the same logic as LAN.
Playing remotely through a domain or public IP. See below.
Unless you plan to play completely locally or over a VPN, you will need to port forward for players outside of your network to access the server. The general idea of port forwarding is when a client sends a request to the server (with a specific port), a properly set up port forward will allow the request to go through and to the specified host. Terraria uses 7777 by default but you can change this in your config file.
If you do not have access to your network infrastructure, you will need to resort to either playing over LAN or a VPN.
Head to your router web interface by typing your gateway IP into your router. It might be 192.168.1.1, 172.1.0.1 or something else. This will vary depending on how your network is setup.
Find the port forwarding section. Your router management software is probably going to be different but theres a good chance that its just called "port forwarding" or under a "NAT" tab or something of the likes. EX: For PFsense, it is under NAT and is called Port Forwarding. Your inputs may also look a little different. Please consult your software manufactuerers manual for guidance if you do not know what you are doing.
Set the external or incoming port. This is the port that players will type when they try to join your server.
Set the internal or outgoing port. This is the port that will be used by Docker. This is the first part of the -p 7777:7777.
The second part is the container port. This is what you put into your server config (7777 by default).
Set your destination IP. This will be the IP of your server/host. There are many ways to find it. Go to your terminal: Windows is ipconfig. Most Linux distros have ip a or ifconfig or a similar command. Look for your interface, whether it is wifi or wired, and find your IPV4 address. It might look like 192.168.1.XXX or 172.1.0.XXX. Again, will probably be different.
Note
Your public IP might eventually change if it is not static. You can work around this with a DDNS like DuckDNS or FreeDNS.
You will also need a port. If you didn't change the defaults, it will just be 7777. If you did change from defaults, it will be whatever port you set as your external port in your router.
More info on the Fandom and at whatismyip.com/port-forwarding/.
You can run the command docker exec <container name> inject "<command>" to inject a command directly into the server. An example: docker exec terraria inject "say Hello from the server!"
More info on the Terraria Wiki.
If you would like for the container to not attempt to download dotnet every boot, then add a volume flag to your container to /opt/terraria/server/dotnet/. Ex: -v <config_dir>/dotnet_cache.
Just beware that there could be versioning issues in the future if the target dotnet runtime version is updated, hence why the dotnet runtime is not saved by default.
Assuming you did everything correctly, you should have a functional server that will automatically load the world upon start.
Have fun!
rfvgyhn for the server injection functionality.
Content type
Image
Digest
sha256:682d93250…
Size
128.6 MB
Last updated
about 2 months ago
docker pull passivelemon/terraria-docker