Docker Node With Multiple IP Addresses - Switching Between Them

My network configuration looks something like this on a docker host:

➜  server git:(master) ✗ ip addr
3: ens9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether 00:02:c9:bb:3b:f4 brd ff:ff:ff:ff:ff:ff
    inet <IP Address>.18/29 brd <Default Gateway>.23 scope global ens9
       valid_lft forever preferred_lft forever
    inet <IP Address>.19/29 brd <Default Gateway>.23 scope global secondary ens9:0
       valid_lft forever preferred_lft forever

Currently, I have existing non-Docker services running on port 443 on the .18 IP address, and I need to keep it that way. However, when I open a port using a Dockerfile, it fails to start because port 443 is already in use by the host.

Is there a way to globally switch the IP address that Docker uses when opening a port up? I do not want to have to set this manually on each container's configuration file, which of course already works.

You don't need to expose ports to access certain containers on the service declaration. In fact, you can declare a network inside a single docker-compose.yml with a different subnet like this:

version: '2'

networks:
  custom-network:
    ipam:
      driver: default
      config:
        - subnet: 73.0.0.0/16
          ip_range: 73.0.0.0/24
          gateway: 73.0.0.254

services:
  simple-nginx:
    image: nginx
    networks:
      custom-network:
        ipv4_address: 73.0.0.10

And access the nginx service using the static IP 73.0.0.10 for the custom-network.

For more information, you can always check the networking docs for docker-compose: https://docs.docker.com/compose/networking/

Or directly the docker docs: https://docs.docker.com/engine/userguide/networking/