When I do curl on a it works, on b I get: curl: (6) Could not resolve host:
As seen above the difference between a and b is only some ports published.
Is there a way where a service has a published port but can also access the internet?
Since you quoted compose file has an indentation error, I’m surprised it works at all. Maybe Swarm ignores it somehow. Try to fix the indentaion of the network keyword .
What you experience is not caused by published ports. There must be an underlying problem that causes this behavior.
Is this a multi node setup, and are both containers running on different nodes? Does it happen if both run on the same node? It might be a problem with the overlay network.
The teat is successful meaning that i successfully can curl so I was able to rule out network isn’t the issue.
When ports are not exposed on service b it is able to access the internet. The only difference is expose or not.