Static ipv4 for container in pre-existing (external) network?

@rubendario thanks for the help. I finally found a way to do it in version 3.

version: '3'

services:
  nginx:
    image: nginx
    container_name: nginx
    networks:
      nginx-proxy:
        ipv4_address: "172.20.0.123"
    ports:
      - "80:80"
      - "443:443"

networks:
  default:
    external:
      name: nginx-proxy
  nginx-proxy:
    external: true

Apart from defining the default network, you need to explicitly define that its external network.

1 Like