Skip to content

[BUG] extra_hosts in docker compose 2.37.0 (latest version) doesn't work #12926

Closed

Description

@alirezarpi

Description

After a lot of investigation we found out that newest version of docker compose (2.37.0) extra_hosts is not working as expected.
as we ran cat /etc/hosts with latest docker:dind which was using the mentioned version the result was NOT as bellow which we were expecting:

#7 [service-email 4/5] RUN cat /etc/hosts
#7 0.089 127.0.0.1	localhost buildkitsandbox
#7 0.089 ::1	localhost ip6-localhost ip6-loopback
#7 0.089 172.17.0.1	host.docker.internal

it was actually missing 172.17.0.1 host.docker.internal part. it got fixed when we downgraded to docker:28.2.2-dind-alpine3.21.

Steps To Reproduce

using mentioned version (latest for now)

docker-compose:

services:
  test:
    image: test
    build:
      context: .
      dockerfile: ./Dockerfile
      args:
        - PROFILE=$PROFILE
      extra_hosts:
        - "host.docker.internal=172.17.0.1"

and in Dockerfile run curl command against the host.docker.internal:2375
will result in:

> [5/5] RUN curl -IvL host.docker.internal:2375:
                           Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* Could not resolve host: host.docker.internal
0.436 * Closing connection
0.436 curl: (6) Could not resolve host: host.docker.internal

Compose Version

2.37.0

Docker Environment


Anything else?

No response

Activity

  1. ndeloof commented on Jun 11, 2025

    @ndeloof
    Contributor

    This is related to docker/buildx#494
    v2.37.0 use Docker Bake as build backend by default, you can temporary opt-out by setting COMPOSE_BAKE=false

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions