Whats the correct way to deal with networks in a multi-container app?
In the following example there are 3 containers; db, memcached and seafile
Ordinarily without traefik involved, they are all a part of the 'seafile-net' network as defined in the docker-compose.yml file.
Traefik is attached to the network 'traefik', and so I have attached the main app in the seafile docker-compose.yml to the 'traefik' network, since I don't want the 'db' or the 'memcached' containers on that network. This means that the 'seafile' container is on 2 networks 'traefik' and 'seafile-net'.
This seems to work.... sometimes, not always, and so I have to bring the app up and down until it works. This is the case with other apps I have, which are composed in a similar manner.
If I place all of the containers in the app on the 'traefik' network, everything works fine, first time.
I would just like to know, what is the correct way to deal with this?
services:
db:
image: mariadb:10.11
container_name: seafile-mysql
environment:
- MYSQL_ROOT_PASSWORD="mypassword" # Required, set the root's password of MySQL service.
- MYSQL_LOG_CONSOLE=true
- MARIADB_AUTO_UPGRADE=1
volumes:
- /opt/seafile/seafile-mysql/db:/var/lib/mysql # Required, specifies the path to MySQL data persistent store.
- "/var/run/docker.sock:/var/run/docker.sock:ro"
networks:
- seafile-net
# - traefik
memcached:
image: memcached:1.6.18
container_name: seafile-memcached
entrypoint: memcached -m 256
networks:
- seafile-net
# - traefik
seafile:
image: seafileltd/seafile-mc:11.0-latest
container_name: seafile
ports:
- "8081:80"
# - "443:443" # If https is enabled, cancel the comment.
labels:
- "traefik.enable=true"
- "traefik.http.routers.seafile.rule=Host(`seafile.mydomain.xyz`)" # && (PathPrefix(`/login`))"
- "traefik.http.routers.seafile.tls=true"
- "traefik.http.routers.seafile.entrypoints=websecure"
- "traefik.http.routers.seafile.tls.certresolver=myresolver"
- "traefik.http.services.seafile.loadbalancer.server.port=80"
volumes:
- /tragopan-share/seafile:/shared # Required, specifies the path to Seafile data persistent store.
- "/var/run/docker.sock:/var/run/docker.sock:ro"
environment:
- DB_HOST=db
- DB_ROOT_PASSWD="mypassword" # Required, the value should be root's password of MySQL service.
- TIME_ZONE=Etc/UTC # Optional, default is UTC. Should be uncomment and set to your local time zone.
- SEAFILE_ADMIN_EMAIL=admin@mydomain.xyz # Specifies Seafile admin user, default is 'me@example.com'.
- SEAFILE_ADMIN_PASSWORD=mypassword # Specifies Seafile admin password, default is 'asecret'.
- SEAFILE_SERVER_LETSENCRYPT=false # Whether to use https or not.
- SEAFILE_SERVER_HOSTNAME=seafile.mydomain.xyz # Specifies your host name if https is enabled.
depends_on:
- db
- memcached
networks:
- traefik
- seafile-net
networks:
seafile-net:
traefik:
external: true