Docker 组合忽略容器中的 ipv4_address

Mar*_*cak 2 docker docker-compose

我有以下 docker-compose.yaml 文件

version: "3.9"
services: 
  box1:
    hostname: box1
    build:
      context: .
      dockerfile: box.Dockerfile
    networks:
      testing: 
        ipv4_address: 172.28.1.10
    command: |
      /bin/sh -c 'while true; do sleep 1; done'
  box2:
    hostname: box2
    build:
      context: .
      dockerfile: box.Dockerfile
    networks:
      testing: 
        ipv4_address: 172.28.1.20
    command: |
      /bin/sh -c 'while true; do sleep 1; done'
  box3:
    hostname: box3
    build:
      context: .
      dockerfile: box.Dockerfile
    networks:
      testing: 
        ipv4_address: 172.28.1.30
    command: |
      /bin/sh -c 'while true; do sleep 1; done'
networks:
  testing:
    driver: macvlan
    driver_opts:
      parent: eth0
    ipam:
      driver: default
      config:
        - subnet: 172.28.1.0/24
          gateway: 172.28.1.1/
          aux_addresses: 
            box1: 172.28.1.10
            box2: 172.28.1.20
            box3: 172.28.1.30
Run Code Online (Sandbox Code Playgroud)

我在互联网上尝试了所有组合和提示,但无论我尝试什么,docker compose 都会为容器分配另一个 IP 地址,然后是我在规范中使用的那些。

当我尝试docker exec box_1 /bin/sh -c 'ifconfig'dig为另一个容器的DNS,我越来越随机IP地址,而不是那些为每个容器设置。

我正在为 mac 3.3.1 运行 docker 桌面 (63152)

小智 7

docker compose up在 macOS 上使用时遇到了类似的问题。使用docker-compose up(注意-符号)解决了它。