0

I have made a dockerfile and docker-compose file that run a node.js application. My plan was to use it for testing out scaling with replicas without fancy load balancers.

My app works well when I start it with sudo docker-compose -p "myapp" up. Than I bring it down before trying to deploy it with:

sudo docker-compose -p 'myapp' down --volumes
sudo docker-compose -p 'myapp' push

If I than run:

sudo docker stack deploy -c docker-compose.yml 'myapp'

it gives me this error and I don't understand what could be causing it or how to troubleshoot it:

1 error(s) decoding:

* error decoding 'Ports': No port specified: :<empty>

This is my docker-compose.yml:

version: '3.3'
services:
  app:
    build: ./
    restart: always
    env_file: ./.env
    ports:
      - 3306:3306
    network_mode: host
    stdin_open: true
    tty: true
    deploy: 
      mode: replicated
      replicas: 12
      update_config:
        parallelism: 11
volumes: 
  db:

I was roughly following this tutorial.

Janez Kranjski
  • 115
  • 2
  • 10
  • 1
    `network_mode: host` generally disables Docker networking, and it's incompatible with `ports:`. You shouldn't need it for most practical applications; does deleting that option make a difference at all? – David Maze Jan 29 '22 at 15:41
  • @DavidMaze yep I use it to connect to localhost because I don't run my database in docker. If I try to connect to my db without it I get ECONNREFUSED. I would need a different way to getting localhost(outside of the container) – Janez Kranjski Jan 29 '22 at 16:42
  • You also tagged this with [tag:docker-swarm]; do you run a separate replica of the database on each node of the cluster? Have you looked at other questions like [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) that discuss accessing non-container processes from inside a container? – David Maze Jan 29 '22 at 17:04
  • I run only one db and want to make multiple connections. I have looked into that thread but `--network="host"` was the only one I could get to work. host.docker.internal doesn't work, bridging doesn't work, getting command line data in env doesn't work.... – Janez Kranjski Jan 29 '22 at 17:41
  • you might want to put ports in double quotes like `"3306:3306"` – pavan kumar Jan 29 '22 at 19:17
  • We've narrowed down the problem to be `network_mode: host` and I need to figure out how to connect my local mysql database to the docker container but I don't know how I'd do it without it... – Janez Kranjski Jan 29 '22 at 19:27
  • With host networking, why do you feel you need ports defined at all? Simply delete the ports section. Or better, avoid connecting to localhost by providing a routeable ip to your app. – BMitch Jan 30 '22 at 00:53

0 Answers0