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:
- The first wordpress stack starts successfully. Everything is fine so far
- 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