Docker & DevOps

Host a Valheim Dedicated Server with Docker

Run a Valheim dedicated server with Docker on a Linux VPS — compose file, UDP ports, persistent world data and safe updates.

IntermediateLinux server6 min read

A Valheim dedicated server with Docker gives you a world that stays online when your own PC is off, and it keeps the world files in a Docker volume you can back up. This guide walks through the compose file, the UDP ports Valheim needs, where the world data lives, and how to update the server without wiping anyone's progress.

You will end up with a container that restarts on boot, a world named in the compose file, and a Steam join address your friends can use.

Before you start

You need:

  • A Linux VPS with at least a few gigabytes of RAM. Valheim worlds grow as players build, so leave headroom.
  • Ubuntu 22.04/24.04, Debian 12, AlmaLinux or Rocky 8–9.
  • A non-root user with sudo. The examples use deploy.
  • Your server's public IP — 203.0.113.10 in the examples.
  • Docker and Docker Compose installed. If you have not done that yet, follow Install Docker and Docker Compose on a Linux VPS first.

Note: The community image used here is maintained by volunteers, and its environment variable names change occasionally. Check the image's own documentation before you rely on a variable that is not in this guide.

Install Docker and Docker Compose

If Docker is already running, confirm it:

Bash
docker --version
docker compose version

If either command is missing, install Docker from the official repository using the guide linked above, then add your user to the docker group so you do not need sudo for every command:

Bash
sudo usermod -aG docker deploy

Log out and back in for the group change to apply.

Write the Compose file

Create a directory for the stack:

Bash
mkdir -p ~/valheim && cd ~/valheim

Create a .env file for the server password so it does not sit in the compose file:

INI
VALHEIM_PASS=change-this-to-a-long-password

Now create compose.yaml:

YAML
services:
  valheim:
    image: lloesche/valheim-server:latest
    container_name: valheim
    cap_add:
      - sys_nice
    stop_grace_period: 2m
    ports:
      - "2456:2456/udp"
      - "2457:2457/udp"
    environment:
      SERVER_NAME: "My Valheim Server"
      WORLD_NAME: "Midgard"
      SERVER_PASS: "${VALHEIM_PASS}"
      SERVER_PUBLIC: "false"
      TZ: "Europe/London"
    volumes:
      - valheim-config:/config
      - valheim-data:/data
    restart: unless-stopped

volumes:
  valheim-config:
  valheim-data:

Two things matter here. First, stop_grace_period: 2m gives the server time to write the world to disk when Docker stops the container — without it you risk losing the last few minutes of play. Second, the two named volumes keep your world and configuration outside the container, so pulling a new image never touches them.

Tip: Valheim rejects passwords shorter than five characters, and it also rejects a password that appears inside the server name. Keep them unrelated.

Open the Valheim ports

Valheim uses UDP, not TCP. The game port is 2456 and the Steam query port is 2457. Open both:

Bash
sudo ufw allow 2456/udp
sudo ufw allow 2457/udp
sudo ufw status

On AlmaLinux or Rocky with firewalld:

Bash
sudo firewall-cmd --permanent --add-port=2456/udp
sudo firewall-cmd --permanent --add-port=2457/udp
sudo firewall-cmd --reload

Warning: Only open the ports you need. Do not disable the firewall to "test" connectivity — open the two UDP ports and leave the rest closed.

If your provider also has a firewall or security group in front of the VPS, add the same two UDP ports there. A blocked UDP port is the single most common reason a server never appears in the Steam browser.

Start the server and watch the logs

Bring the stack up:

Bash
docker compose up -d
docker compose logs -f valheim

The first start downloads the Valheim dedicated server files through SteamCMD, which takes a few minutes. You are waiting for a line that says the game server is listening, followed by the world name. Press Ctrl+C to leave the log view — the container keeps running.

Check the container state:

Bash
docker compose ps

You want running, not restarting or exited.

Connect from Steam

In Valheim, open the join menu and use Join game with the address:

203.0.113.10:2456

The client connects on the game port, not the query port. If you set SERVER_PUBLIC: "false", the server will not be listed publicly — friends join by IP or through the Steam friends list. Set it to "true" if you want it visible in the in-game browser.

Update the Valheim dedicated server safely

Valheim patches break compatibility between client and server versions, so update when your players are offline.

Warning: Stop the server before updating. Pulling a new image while the world is live can interrupt a save and corrupt the current world file.

Bash
cd ~/valheim
docker compose stop
docker compose pull
docker compose up -d
docker compose logs -f valheim

docker compose stop sends a graceful shutdown, and the two-minute grace period lets the world save finish. Because the world lives in the valheim-data volume, the new container picks up exactly where the old one left off.

If a new image turns out to be broken, pin the previous tag in compose.yaml and bring the stack back up — the same idea as rolling back a bad deploy using Docker image tags.

Check it works

Confirm the container is listening on UDP:

Bash
sudo ss -lunp | grep -E '2456|2457'

You should see the Docker proxy bound to both ports. Then:

  1. Connect from your own Valheim client using 203.0.113.10:2456.
  2. Place a marker or build a small structure, then disconnect.
  3. Restart the container with docker compose restart and reconnect. Your build should still be there — that proves the volume is doing its job.

Troubleshooting

  • Server never appears in the Steam browser → the query port is blocked or SERVER_PUBLIC is "false". Confirm 2457/udp is open at both the OS and provider firewall, and check the logs for the query port line.
  • "Password must be at least 5 characters" or the container exits at startup → the password in .env is too short, or it is contained in SERVER_NAME. Change both and run docker compose up -d again.
  • World resets after an update → the /data volume is missing or was recreated. Run docker volume ls and confirm valheim-data still exists; never run docker compose down -v, which deletes named volumes.
  • Progress lost after a restart → stop_grace_period is too short or missing. Set it to 2m and restart the stack.
  • Clients cannot join after a patch → client and server versions differ. Update the image on the server and update Valheim on every client.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.