0

I'm trying to achieve the following setup:

I have a center stack containing my nginx-proxy stuff. This stack declares a network (let's call it nginx_proxy_net)

Next, I want to setup 2 stacks for 2 wordpress installs, each one of them is totally independant and contains its own wordpress service & mysql service. Both wordpress use the nginx_proxy_net network.

When I try to start my 2 stacks, the following happens:

  1. The first wordpress stack starts successfully. Everything is fine so far
  2. The second wordpress stack refuse to start because port 3306 (mysql) is already in use. The error is: Error response from daemon: rpc error: code = 3 desc = port '3306' is already in use by service 'mywp1_mysql' (qzcqsfvoj3ga2nte11rj3qgum) as an ingress port

I've understood that each exported port is binded on the routing mesh, and I've also understood that you can link your service on several network. So I tried to create a network for each stack, so there is, on each of those stack network, a single MySQL & a single Apache/Wordpress.

Here is my Wordpress stack mywp1 docker-compose.yml:

version: "3"
services:
  web:
    depends_on:
      - mysql
    image: wordpress:4.8-apache
    depends_on:
      - mysql
    ports:
      - 79:80
    volumes:
      - ./data/wordpress:/var/www/html
    networks:
      - mywp1_webnet
      - nginx-proxy
  mysql:
    image: mysql
    ports:
      - 3306:3306
    volumes:
      - ./data/mysql:/var/lib/mysql
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - mywp1_webnet
networks:
  mywp1_webnet:
  nginx-proxy:
    external:
      name: nginx_proxy_default

Here is mywp2

version: "3"
services:
  web:
    depends_on:
      - mysql
    image: wordpress:4.8-apache
    depends_on:
      - mysql
    ports:
      - 78:80
    volumes:
      - ./data/wordpress:/var/www/html
    networks:
      - mywp2_webnet
      - nginx-proxy
  mysql:
    image: mysql
    ports:
      - 3306:3306
    volumes:
      - ./data/mysql:/var/lib/mysql
    deploy:
      placement:
        constraints: [node.role == manager]
    networks:
      - mywp2_webnet
networks:
  mywp2_webnet:
  nginx-proxy:
    external:
      name: nginx_proxy_default

I'm not very experienced with Docker, so maybe I'm about to ask something really stupid: is it possible to expose my ports only on my stacks networks, and not on the ingress? I'd like, as much as possible, keep the defaults.

The question, here, is: is it possible to keep both mysql instances with default ports, without interfering with each other?

Thank you very much, have a nice day

Alex

  • Can you please provide your docker-compose.yml file? – ryekayo Aug 18 '17 at 15:33
  • Done, and I changed a bit the question, because a part of the problem was solved directly by *nginx-proxy* (I must spawn each web application on a different port than 80, because 80 is already used by nginx-proxy.... Sometimes I'm silly) – Alexandre Germain Aug 19 '17 at 09:08

1 Answers1

0

You shouldn't need to publish ports in either of your mywp* compose files. You can use your reverse proxy to reach the website and you should not be hitting your database from outside of the containers. Nginx-proxy is good for a single node cluster, not sure that it's been updated for swarm mode yet, so you may want to consider a swarm aware proxy like traefik.

If for some reason you need to directly connect to your database from outside of your swarm cluster, then you'll need to give each app its own port. Running multiple applications on the same port isn't supported outside of docker, so it isn't supported inside of docker either.

BMitch
  • 5,189
  • 1
  • 21
  • 30
  • 1
    Hi, yeah, perfect, I didn't even know that ports were accessible in the stack without even exposing them through the `docker-compose.yml` file. So I just removed the `ports` directive, and it worked like a charm! Thank you for the tip :D – Alexandre Germain Aug 22 '17 at 09:37