How to Set Network Priority in Docker Compose?

0
6
Asked By CuriousCat42 On

Hey everyone! I'm running a container that acts as a downloader for Archive Team Warrior. It's set up to use a specific public IP via a macvlan network that I created. This setup works great for downloading because I've configured my router to NAT the internal IP to that public IP. But here's the kicker: the container has a web UI for management that I usually secure with Nginx Proxy Manager. My Docker host also has a bridge network (named better_bridge) that allows containers to communicate with each other. The problem is that when I configure both the macvlan and the bridge networks in Docker Compose, Docker picks the bridge network by default since it's listed first alphabetically. I know with the Docker CLI, I could start the container with the macvlan and then connect the bridge afterward, but I'm not sure how to achieve this in Docker Compose. Does anyone have a solution for prioritizing one network over the other?

1 Answer

Answered By TechieTimmy On

If you want macvlan to be the default gateway for your container, there's a new option you can use called `gw_priority`. You can set the priority directly in your Compose file like this:

```yaml
services:
your_service:
networks:
your_macvlan:
gw_priority: 1
your_bridge:
```
This should help ensure Docker prefers the macvlan network. Just check that you’re using a compatible version of Docker Compose that supports this feature!

NerdyNina -

Thanks for the tip! I tried this with Portainer, but something was off because it uses an older version. I guess I have to wait for the update and try again. Fingers crossed!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.