This guide walks you through setting up a dedicated Terraria server inside a Docker container on a VPS. You’ll get a persistent, always-on multiplayer world that you can manage from the command line, with automatic restarts and easy backups. Before starting, you need a VPS with a public IP, SSH access, and Docker installed (Docker Engine 20.10 or newer is recommended).
What You’ll Need
- A VPS with at least 2 GB RAM (4 GB is better for larger groups).
- Ubuntu 22.04 or Debian 12 (other distros work, but commands may differ).
- Docker and Docker Compose installed on the VPS.
- SSH client (like PuTTY or the terminal) to access your server.
- Port 7777 open in your firewall (TCP and UDP).
Step-by-Step
- SSH into your VPS – Use your terminal or PuTTY to connect as a user with sudo privileges.
- Install Docker and Docker Compose (if not already present):
curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo apt install -y docker-compose-plugin - Create a directory for the server files:
mkdir -p ~/terraria && cd ~/terraria - Create a docker-compose.yml file with the following content (using the official terraria server image):
services: terraria: image: rickdb/terraria:latest container_name: terraria restart: unless-stopped ports: - "7777:7777" volumes: - ./world:/world - ./config:/config environment: - WORLD_NAME=MyWorld - WORLD_SIZE=1 # 1=small, 2=medium, 3=large - MAX_PLAYERS=8 - PASSWORD=yourpassword - MOTD=Welcome to my Terraria server! - DIFFICULTY=0 # 0=classic, 1=expert, 2=master stdin_open: true tty: true - Start the server:
sudo docker compose up -dThe first start may take a few minutes as it downloads the image and generates the world.
- Check the logs to confirm the server is running:
sudo docker compose logs -fWait for the message “Server started” or similar. Press Ctrl+C to stop following logs.
- Connect from Terraria – In the game, choose Multiplayer → Join via IP, enter your VPS’s public IP and port 7777. Use the password you set if any.
- Manage the server – Use
sudo docker attach terrariato access the console, or usesudo docker exec -it terraria screen -rif the image supports screen. To stop the server gracefully, typeexitin the console or runsudo docker stop terraria.
Common Mistakes
- Forgetting to open the firewall – Even if Docker maps the port, your VPS’s firewall (like UFW) may block it. Allow TCP/UDP 7777:
sudo ufw allow 7777/tcp && sudo ufw allow 7777/udp. - Using the wrong image – Some images are outdated or not maintained. The
rickdb/terrariaimage is widely used, but verify its documentation. - Not persisting data – If you don’t mount volumes for the world and config, you lose everything when the container is recreated. Always use volumes as shown.
- Setting world size incorrectly – The environment variable expects a number (1, 2, or 3), not words like “small”.
- Ignoring server version – The image may not match your Terraria client version. Check the image’s tags and pull a version that matches your game (e.g.,
rickdb/terraria:1.4.4.9).
Tips
- Back up your world regularly – Copy the
~/terraria/worlddirectory to another location or use a cron job. - Use a named volume for easier backups – Instead of bind mounts, you can use
terraria-world:/worldand back up viadocker cp. - Enable autosave – The server autosaves by default, but you can adjust the interval in the config file.
- Set a server password – Always set a password to prevent random players from joining.
- Monitor resource usage – Use
docker statsto see CPU and RAM usage. If the server lags, consider upgrading your VPS.
Troubleshooting
- Server won’t start – Check logs with
sudo docker compose logs. Common issues: missing world directory permissions, or the image expects a different environment variable. Ensure theworldfolder exists and is writable. - Can’t connect from the game – Verify the firewall, the port mapping in docker-compose, and that the server is actually listening (
sudo netstat -tulpn | grep 7777). Also ensure you’re using the correct IP (public, not private). - Players get disconnected frequently – This can be due to network instability or the server running out of memory. Check
docker statsand consider limiting max players. - World not saving – If you don’t see the world file in
~/terraria/world, the volume mount is wrong. The world file is usually namedMyWorld.wld. - How to update the server – Pull the new image and recreate the container:
sudo docker compose pull && sudo docker compose up -d. Your world remains intact.
Frequently Asked Questions
Do I need a powerful VPS for a Terraria server?
A small server (2 GB RAM, 1 vCPU) can handle up to 4-6 players. For 8+ players, go with 4 GB RAM and 2 vCPUs.
Can I run multiple Terraria worlds on the same VPS?
Yes, you can run multiple containers, each with a different port and world name. Just duplicate the service in docker-compose with a different container name and port.
How do I change the world size after creation?
You cannot change the size of an existing world. You must delete the world file and let the server generate a new one with the new size setting.
Is it safe to expose my server to the internet?
Yes, but always set a strong password and keep the server updated. Consider using a firewall to restrict access to trusted IPs if you play with a fixed group.
How do I back up my world?
Simply copy the ~/terraria/world directory to a safe location. You can also use docker cp terraria:/world /backup.
Can I use mods with a Docker server?
Yes, but you need a modded server image. Look for images like rickdb/terraria-tshock or build your own with TShock installed.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- Microsoft Surface Duo: The Foldable Phone Story
- Samsung SM-T813 Hard Reset: Step-by-Step Guide
- Mafia Clash Codes: Real Meanings & Usage
- Remove Programs from Mac: Full Uninstall Guide
- Project Sentinel Morning Digest: Data Stack Failure Alerts
- Best KVM VPS Hosting: Top Picks & Guide