Jamesits / docker-dst-server

Don't Starve Together dedicated server in Docker!
https://hub.docker.com/r/jamesits/dst-server
GNU General Public License v2.0
490 stars 99 forks source link

Documentation on how to host multiple servers on the same machine #10

Closed YuxuanChen closed 5 years ago

YuxuanChen commented 5 years ago

It was easy enough to get this container to work for one server, but I would like to be able to host multiple servers on the same machine. How difficult would it be to support this?

Jamesits commented 5 years ago

As far as I can tell currently:

If you don't need caves server

run multiple instances of this container, expose port 10999 to different external ports, and let users connect using c_connect("IP address", port[, "password"]).

If you need caves server and have multiple IP addresses bonded to your server

you can expose ports on different IPs. See https://docs.docker.com/config/containers/container-networking/#published-ports

If you need caves server and have to reuse the only IP address on your server

Then you have to change the default ports the servers are on. Do the following for every server you need to run:

  1. Run the container once per server to generate default config (docker run -v ~/dst/server_1:/data -it jamesits/dst-server:latest), or copy another working server's config
  2. Open ~/dst/server_1/DoNotStarveTogether/Cluster_1/Master/server.ini, change server_port (e.g. 20000)
  3. Open ~/dst/server_1/DoNotStarveTogether/Cluster_1/Caves/server.ini, change server_port (e.g. 20001)
  4. Run the container again and expose the new ports: docker run -v ~/dst/server_1:/data -p 20000-20001:20000-20001/udp -it jamesits/dst-server:latest
  5. Let user connect to the new port, e.g.: c_connect("192.0.2.2", 20000, "password") in the game console

Steam discovery (global catalog search in the game) will likely to fail but your mileage may vary. IDK about Tencent's service.

I haven't tried this configuration, if you have experiment results (if users can connect use c_connect, if your server shows up in the public catalog and if your server can be connected from the public catalog) please share with me in this thread. Thanks.

YuxuanChen commented 5 years ago

I'm in the third case: I only have 1 IP address and I need 2 worlds:

World1Master World1Caves

World2Master World2Caves

I got World1Master and World1Caves working only. I copied the World2 settings into the World1 data folder as Cluster_2, is that correct? So now, my data folder looks like this:

ls ~/.klei/DoNotStarveTogether/DoNotStarveTogether: Cluster_1 Cluster_2

I changed Cluster_2/Master/server.ini: server_port -> 20000 I changed Cluster_2/Caves/server.ini: server_port -> 20001

Using docker-compose, I exposed these ports as well: 20000-20001:20000-20001.

I ran c_connect("192.168.1.x", 20000, "password") but it doesn't work: Server is not responding. (It works when I am trying to connect to Cluster_1)

Do I need to change master_port in cluster.ini, or master_server_port in Cluster_2/Master/server.ini?

Thanks, Yuxuan Feb 22, 2019, 2:09 AM by notifications@github.com:

As far as I can tell currently:

If you don't need caves server

run multiple instances of this container, expose port 10999 to different external ports, and let users connect using > c_connect("IP address", port[, "password"])> .

If you need caves server and have multiple IP addresses bonded to your server

you can expose ports on different IPs. See > https://docs.docker.com/config/containers/container-networking/#published-ports https://docs.docker.com/config/containers/container-networking/#published-ports

If you need caves server and have to reuse the only IP address on your server Run the container once per server to generate default config: > docker run -v ~/dst/server_1:/data -it jamesits/dst-server:latest Open > ~/dst/server_1/DoNotStarveTogether/Cluster_1/Master/server.ini> , change > server_port> (e.g. 20000) Open > ~/dst/server_1/DoNotStarveTogether/Cluster_1/Caves/server.ini> , change > server_port> (e.g. 20001) Run the container again and expose the new ports: > docker run -v ~/dst/server_1:/data -p 20000-20001:20000-20001/udp -it jamesits/dst-server:latest Let user connect to the new port, e.g.: > c_connect("192.0.2.2", 20000, "password)> in the game console

Steam discovery (global catalog search in the game) will likely to fail but your mileage may vary.

I haven't tried this configuration, if you have experiment results please share with me in this thread. Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, > view it on GitHub https://github.com/Jamesits/docker-dst-server/issues/10#issuecomment-466345077> , or > mute the thread https://github.com/notifications/unsubscribe-auth/AF_hdyp-XBUlIVbtZINaFXbeW9axM_P_ks5vP8HbgaJpZM4bJLZX> .

Jamesits commented 5 years ago

No, you should copy your inner DoNotStarveTogether directory to another place rather than creating Cluster_2.

Like I've stated, if you need to run 2 different servers, you should map 2 different directories to /data for 2 containers:

docker run -v ~/dst/server_1:/data ...
docker run -v ~/dst/server_2:/data ...

The directory structure will look like:

.
├───server_1
│   └───DoNotStarveTogether
│       └───Cluster_1
│           ├───Caves
│           └───Master
└───server_2
    └───DoNotStarveTogether
        └───Cluster_1
            ├───Caves
            └───Master
YuxuanChen commented 5 years ago

Ahh I see, does this mean I need to run two instances of the docker container?

Feb 22, 2019, 10:21 PM by notifications@github.com:

No, you should copy your inner > DoNotStarveTogether> directory to another place rather than creating > Cluster_2> .

Like I've stated, if you need to run 2 different servers, you should map 2 different directories to > /data> for 2 containers:

docker run -v ~/dst/server_1:/data ...docker run -v ~/dst/server_2:/data ...

The directory structure will look like:

.├───server_1│ └───DoNotStarveTogether│ └───Cluster_1│ ├───Caves│ └───Master└───server_2 └───DoNotStarveTogether └───Cluster_1 ├───Caves └───Master

— You are receiving this because you authored the thread. Reply to this email directly, > view it on GitHub https://github.com/Jamesits/docker-dst-server/issues/10#issuecomment-466621596> , or > mute the thread https://github.com/notifications/unsubscribe-auth/AF_hd1FYF4Mvf1KHnEvaLIk3H9TtMHMuks5vQN3wgaJpZM4bJLZX> .

Jamesits commented 5 years ago

Yes

YuxuanChen commented 5 years ago

Thanks a lot for your help! Here is the docker-compose file that I used to get my servers up and running simultaneously (it's confirmed to work for me):

version: "3"
services:
  dst-server-1:
    container_name: dst-server-1
    image: jamesits/dst-server:latest
    deploy:
        restart_policy:
            condition: always
    ports:
        - "10999-11000:10999-11000/udp"
        - "12346-12347:12346-12347/udp"
    volumes:
        - ~/.klei_1/DoNotStarveTogether:/data
    stop_grace_period: 2m

  # dst-server-2:
  #   container_name: dst-server-2
  #   image: jamesits/dst-server:latest
  #   deploy:
  #       restart_policy:
  #           condition: always
  #   ports:
  #       - "20999-21000:20999-21000/udp"
  #       - "22346-22347:22346-22347/udp"
  #   volumes:
  #       - ~/.klei_2/DoNotStarveTogether:/data
  #   stop_grace_period: 2m