Docker Community Forums

Share and learn in the Docker community.

How to create network connection into remote docker stack?

Hi, I am struggling to set this up correctly. I am trying to run an app with docker stack deploy on a remote machine. The following app works, when I deploy it with docker swarm deploy on my windows notebook. But when I run it on the linux cluster. I cannot connect to it. If can help me to identify the missing piece here? When I run the app locally, I get some output from curl localhost:8000, however, not at the remote machine. There I get curl: (7) Failed to connect to localhost port 8000: Connection refused. I also do not understand why I get a different result (app accessible, not accessible) on local and remote computer, i.e. what configuration is the disrupting element.

I tried pruning all the networks and start again from scratch.

I opened a stackoverflow question on this, but the answer that I got so far did not help me.

First, I connect to a remote server via ssh:

ssh -qy -L 8000:localhost:8000

Here, I start a web application with docker stack, with this simple yaml file testapp.yml:

    version: '3'
         image: mysql:5.7
           - db_data:/var/lib/mysql
         restart: always
           MYSQL_ROOT_PASSWORD: somewordpress
           MYSQL_DATABASE: wordpress
           MYSQL_USER: wordpress
           MYSQL_PASSWORD: wordpress
           - db
         image: wordpress:latest
           - web_data:/var/www/html
           - "8000:80"
         restart: always
           WORDPRESS_DB_HOST: db:3306
           WORDPRESS_DB_USER: wordpress
           WORDPRESS_DB_PASSWORD: wordpress
           WORDPRESS_DB_NAME: wordpress
        db_data: {}
        web_data: {}

And deploy this with

docker swarm deploy -c testapp.yml testapp

Now, I get the following output with sudo docker stack services testapp:

ID             NAME                MODE         REPLICAS   IMAGE              PORTS
93rj1ialspj2   testapp_db          replicated   1/1        mysql:5.7          
nl18a7mr4auk   testapp_wordpress   replicated   1/1        wordpress:latest   *:8000->80/tcp

However, when I navigate to localhost:8000 there is

This site can’t be reached. localhost refused to connect.

And curl localhost:8000 (on both systems, local and remote) returns

curl: (7) Failed to connect to localhost port 8000: Connection refused

Running docker 20.10.9 remotely and 20.10.8 locally.

To my understanding it should work like this. I have no idea where the error is.