Setting container's ip4Address inside a specific network

I am trying to set the ip4Address of a specific container inside a specific network. Currently my setup is as follow:

  • I have 3 services (vts, provisioning, verification) each in its own docker container
  • I have 2 networks (vts-prov, vts-ver)

The uses of the networks I defined are as followed:
vts-prov - for communication between the provisioning and vts services
vts-ver - for communciation between the verification and vts services

The containers are put into the relevant networks so communication is only allowed between vts<—>provisioning and vts<—>verification. provisioning and verification services are not allowed to communicate with each other.

Below is my docker compose file:

version: '3.8'

services:
  provisioning:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: provisioning-build
    ports:
      - 8888:8888
    networks:
      - vts-prov

  verification:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: verification-build
    ports:
      - 8080:8080
    networks:
      - vts-ver


  vts:
    build:
      context: .
      dockerfile: ./Dockerfile
      target: vts-build
    networks:
      vts-prov:
        ipv4_address: 172.28.0.5
      vts-ver:
        ipv4_address: 172.28.0.5

networks:
  default:
    external: true
    name: none

  vts-prov:
    ipam:
      driver: default
      config:
        - subnet: 172.28.0.0/16

  vts-ver:
    ipam:
      driver: default
      config:
        - subnet: 172.29.0.0/16

When i set the ip4Address of vts to 172.28.0.5, inside for example the vts-prov network, below is the current output after runnning docker compose and docker network inspect services_vts-prov

[
    {
        "Name": "services_vts-prov",
        "Id": "9fb01a21381814335832d5a39875b2f76e34d9536214740d28387548835b998c",
        "Created": "2022-10-21T16:13:21.738497631Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.28.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "40eb39dac1b86cd030328614bfe4cfa7f9488d7f510f94ad154ec9e3bb3b8771": {
                "Name": "services_vts_1",
                "EndpointID": "0e15768832142d872608d104ec9c39128fe859ba4bed1a879612a99d2a522d17",
                "MacAddress": "02:42:ac:1c:00:02",
                "IPv4Address": "172.28.0.2/16",
                "IPv6Address": ""
            },
            "ab9b5d8ce94379f6cd57239270c52bed5e53cce63401d46ecf91faf632f8ab7a": {
                "Name": "services_provisioning_1",
                "EndpointID": "b5c9ec7d6b35ebb20c2cfe480010a264988108b6d92e47a98ed6a1fae3ef77bd",
                "MacAddress": "02:42:ac:1c:00:03",
                "IPv4Address": "172.28.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "vts-prov",
            "com.docker.compose.project": "services",
            "com.docker.compose.version": "1.0-alpha"
        }
    }
]

You can see that the IPv4Address for services_vts_1 is not being set to 172.28.0.5 as I specify in the docker-compose.yaml. The same thing is happening for the other network vts-ver that I have specificed. Please can someone help me understand why this is happening, or whether I am misunderstanding something?

Thank you in advance

1 Like