Caddy/Docker won't comply... as usual.

So… I am trying to use Swordbattle with Docker and Caddy. This is my docker-compose:

version: '3.3'

    image: swordbattleio
    build: .
      - 3300:3300
      - PORT=3300

    image: caddy
      - 80:80
      - 443:443
      - ./Caddyfile:/etc/caddy/Caddyfile

And this is my Caddyfile:

swordio-docker.REDACTED.REDACTED {
  reverse_proxy localhost:3300

When running docker-compose up, everything looks ok, Swordbattle works at (domain):3300, but when i go to the domain:

{"level":"error","ts":1697901854.7101161,"logger":"http.log.error","msg":"dial tcp connect: connection refused","request":{"remote_ip":"MYIP","remote_port":"63673","client_ip":"MYIP","proto":"HTTP/2.0","method":"GET","host":"","uri":"/","headers":{"User-Agent":["Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36"],"Sec-Fetch-Site":["none"],"Sec-Fetch-User":["?1"],"Accept-Language":["en-US,en;q=0.9"],"Cache-Control":["max-age=0"],"Sec-Ch-Ua":["\"Chromium\";v=\"118\", \"Google Chrome\";v=\"118\", \"Not=A?Brand\";v=\"99\""],"Sec-Ch-Ua-Mobile":["?0"],"Upgrade-Insecure-Requests":["1"],"Cookie":[],"Sec-Ch-Ua-Platform":["\"Windows\""],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7"],"Sec-Fetch-Dest":["document"],"Sec-Fetch-Mode":["navigate"],"Accept-Encoding":["gzip, deflate, br"]},"tls":{"resumed":false,"version":772,"cipher_suite":4865,"proto":"h2","server_name":"swordio-docker.REDACTED.REDACTED"}},"duration":0.00081531,"status":502,"err_id":"mcxn67e7z","err_trace":"reverseproxy.statusError (reverseproxy.go:1265)"}

Any help appreciated :smiley:

Easy solution: Don’t use docker, smh

@9pfs That’s not an option. I need it to work

Then make one big docker container

1 Like

Fairly new to docker… would you mind providing me with the code I would need to get Caddy/Swordbattle to work together as I’m trying to do

I’ve never used caddy or docker. Honestly, real devs just deploy to production with each program running in its own home dir on their main system.

1 Like

Darn… It’s required for what I’m doing though as I will have a fleet of these servers.

How will you be running it on each server?

1 Like

They will download Docker, and then pull everything necessary, build, start

Just make a shell script that runs as root in the container during docker container build and:

  • creates a user for swordbattle
  • installs + builds swordbattle as that user
  • installs caddy
  • configures caddy
  • installs runit
  • creates a /etc/runsvdir.d directory in the container + creates a subdirectory for each service (i.e. caddy, swordbattle) in that directory + writes an executable shell script that starts the service in a run file in each subdirectory (MAKE SURE TO DROP PRIVILEGES FOR SWORDBATTLE!!!)

That way, you can use docker, but only need one container.

That just makes Docker itself pointless though it just turns it into a VM. Anyways, how can I do that?

Are you getting paid to set it up?

1 Like

Yes. I need it done quickly, and preferably not just by turning it into a docker vm

edit: I DID IT!

How did you solve it exactly?

Connecting them with networks and telling caddy to reverse proxy swordbattleio:3300