I'm facing difficulties while trying to use Docker Swarm on a VM. The same process worked perfectly on my local machine.
I initialized Docker Swarm on the VM with the command:
docker swarm init --advertise-addr MY_IP_HERE
Then:
docker stack deploy -c docker-swarm.yml app_name
For example, docker-swarm.yml:
version: '3.9'
services:
nginx:
image: nginx:latest
ports:
- 80:80
networks:
- global
networks:
global:
driver: overlay
In the terminal:
docker service ls
Output:
ID NAME MODE REPLICAS IMAGE PORTS
5ns3ui99o82a app_nginx replicated 1/1 nginx:latest *:80->80/tcp
In the terminal:
curl http://localhost or my_ip
Output:
curl: (7) Failed to connect to localhost port 80 after 0 ms: Connection refused
I believe it is related to the network portion, but I don't know what to do, as if I weren't exposing port 80:80. However, on my computer, it exposes normally. This only happens on the VM.