0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

docker-compose でstatic IPが効かなくなった

Posted at

Windows でdocker のCompose のバージョンが 2.0.0 beta3 で発生する。

Use Docker Compose V2 にチェックがついているとdocker-compose でstatic IPが効かなくなる。

設定画面.png

実際に現象を再現してみた。

docker-compose.yml
version: '3.7'
networks:
  test_net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 192.168.200.0/24
services:
  web1:
    image: nginx:1.21.0
    networks:
      test_net:
        ipv4_address: 192.168.200.99
  web2:
    image: nginx:1.21.0
    networks:
      test_net:
        ipv4_address: 192.168.200.55

上記の docker-compose を起動し、「docker network inspect」 で中身を見ると。。。

[
    {
        "Name": "staticip_test_net",
・・・省略
        "Containers": {
            "a3ab1409bc037753f51d6a0e5f77418b0ffefca9e9ba8b909113fe473c6dba32": {
                "Name": "staticip_web2_1",
                "EndpointID": "f0d078ccc32079a014764c0165a0e5910afb4c6b6dcbc8fa10a0156823abf7fc",
                "MacAddress": "02:42:c0:a8:c8:03",
                "IPv4Address": "192.168.200.3/24",
                "IPv6Address": ""
            },
            "c5df265fe1ed684f62b0287da6d48a5cb40c98b78d40fce344734dc8805cb76b": {
                "Name": "staticip_web1_1",
                "EndpointID": "7d76f0ef4d4024fe2b5ed68c6534793b233333d90f0b7945f8b26ec696346946",
                "MacAddress": "02:42:c0:a8:c8:02",
                "IPv4Address": "192.168.200.2/24",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "test_net",
            "com.docker.compose.project": "staticip",
            "com.docker.compose.version": "1.0-alpha"
        }
    }
]

192.168.200.99 と 192.168.200.55になってない。ちゃんと動くようにするには、Use Docker Compose V2 にチェックを外すのが正解だ。いつチェック入れたのか・・・
設定画面2.png
設定後に再度docker-compose を起動したネットワーク構成は下記の通りになる。

[
    {
        "Name": "staticip_test_net",
・・・省略
        "Containers": {
            "6f00d4bb2e5ce7c458ec4f74b95fa86a48448eb691f36ce52612605307906c85": {
                "Name": "staticip_web2_1",
                "EndpointID": "8ba37672b74c698586cd83d3e19663ac99a276e51542243d366daf538aeb1e6d",
                "MacAddress": "02:42:c0:a8:c8:37",
                "IPv4Address": "192.168.200.55/24",
                "IPv6Address": ""
            },
            "b3a8fb91b2f7b6723aeedb3d0f3171a42077aeebe2ad8d15edb4c0ca30cf4f5b": {
                "Name": "staticip_web1_1",
                "EndpointID": "0e5023e90143f97ba6b50a6a98e4b8edc5cbc4dbf465a93f1afa7e71ca42f35d",
                "MacAddress": "02:42:c0:a8:c8:63",
                "IPv4Address": "192.168.200.99/24",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {
            "com.docker.compose.network": "test_net",
            "com.docker.compose.project": "staticip",
            "com.docker.compose.version": "1.29.2"
        }
    }
]

ちゃんとIPアドレスが指定された。めでたしめでたし。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?