Docker Community Forums

Share and learn in the Docker community.

I need to force a service to connect to database using specific network

On this perticular host I have quite a few docker-compose structures running, many of them with mysql databases.

When I try to add a new on this perticular app(service) seems to use another (needed) network to communicate with the result that it’s connecting to another mysql instance from another compose file.

Below my compose file:

version: ‘3’

services:
db:
image: mariadb
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
restart: always
volumes:
- ./db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=xxxx
env_file:
- db.env
networks:
backend_next:

app:
image: nextcloud:apache
restart: always
volumes:
- ./nextcloud:/var/www/html
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini
environment:
- MYSQL_HOST=db
- VIRTUAL_HOST=next.xxx.xxxx.site
- LETSENCRYPT_HOST=xxx.xxxx.site
- LETSENCRYPT_EMAIL=xxxx@xxxx.com
env_file:
- db.env
depends_on:
- db
networks:
backend_next:
proxy_proxy-tier:

networks:
backend_next:
proxy_proxy-tier:
external: true

I absolutely need the proxy_proxy-tier network so that app can be routed by the proxy and I would need app to connect to db using the backend_next network.

But what happens is that app uses the proxy network and actually connects with another mysql instance that is running on that same host.

Does somebody know how I can make app specifically use backend_next for the database connection?

Help much appreciated.

Please re-post your docker compose declaration as preformatted text </>

it looks like my problem is solved.

In another compose file I had something like this:

service:
app
network
default

app_1

And at the bottom of the compose file:
networks:
default:
external:
name: proxy_proxy-tier

So it looks, not sure I quite understand how it works in details, that this made the proxy network default for all other containers on that host.

Does that make any sense?

Anyway since I corrected this and renamed network default to something else everything works fine now.