How do I configure my fly.toml file to work with multiple ports I expose in Dockerfile?

My Dockerfile exposes two ports, 8080 and 49322. One is for a web server and the other for a websocket server.

How do I setup the services part of fly.toml so that there are two ports that accept traffic from the internet? 8080 is already handled, but how do I setup another one for 49322?

I tried adding a copy of the [[services]] used for 8080 and just changed the 8080 and 80 to 49322 instead. What happened then was that the app successfully deployed but visiting it doesn’t even render a page, it couldn’t be reached, the browser just gets an ERR_CONNECTION_RESET.

So any help would be much appreciated.

1 Like

Hi,

It is possible to expose multiple ports. Yes, multiple [[services]] is indeed the way to do it. Strange that didn’t work for you … hmm. Check this Fly app’s fly.toml which exposes multiple ports to see how they do it and compare it to yours to see what you need to do:

Thanks for the suggestion! That file looks exactly like mine except I have another port.

Hold on… I just visited my deployed app and it’s visitable, no more browser error.

So maybe I was simply just experiencing some downtime after a deploy before it actually became reachable? It’s been a couple of hours since I tried deploying it so not sure how long it took for it to become reachable.

I destroyed my app and launched it from scratch again.

And the browser is failing to connect to the page, and it’s been 5+ minutes since deploy was reported ready and app running.

It definitely shouldn’t be doing this, so there’s still something wrong.

I’m wondering why the server isn’t even responding correctly though? That must mean some error beyond what I’m able to see/access.

The logs provided by flyctl says the app is running on the expected ports.

Yet again, I return to the deployed site hours later and it’s reachable.

So at least it’s confirmed that there is some kind of timespan after Fly says it is deployed and running until it actually is.

Strange!

All apps are different and some take longer to start up than others, depending on what they are doing. External stuff etc. You can handle that to some extent using health checks, along with the grace_period value. I’d suggest adding both tcp and http healthchecks to your fly.toml (if not already) with a grace_period. Then Fly will only say the deployment was successful and start routing requests to it once they pass. And if it can reach your app and get a response, well everyone else should be able to (like your browser). Check this part and scroll down: