Skip to content

Replicate --add-host behavior with extra_hosts #12088

@tate-button

Description

@tate-button

Description

In a docker run command, you can add multiple IP addresses for a single hostname. In a compose file, you can only set one IP per host.

docker run --rm --name tester --add-host myhost:0.0.0.1 --add-host myhost:0.0.0.2 alpine cat /etc/hosts

In a compose file, extra_hosts in long syntax won't pass validation if it sees duplicate keys. Short syntax will allow two hosts with the same IP, but overwrites any previous entries with the last entry for the same hostname.

services:
  tester:
    image: alpine
    container_name: tester
    extra_hosts:
      - "myhost=0.0.0.1"
      - "myhost=0.0.0.2"
    command: cat /etc/hosts

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions