Docker Community Forums

Share and learn in the Docker community.

Specifing extra hosts in docker-compose build step

Hello,

I saw on this issue that it was possible to specify extra_hosts in build-stage of docker compose until version 3.

Does anyone has a workaround for this ?

extra_hosts works for me in 3.7

version: "3.7"

services:
  api:
    image: playground
    container_name: api
    init: true
    ports:
      - "3000:3000"
    extra_hosts:
      - "somehost:162.242.195.82"

I mean extra_hosts in build context as it was possible in docker-compose version 2.7 like this:

version: "3"

services:
  app:
    build:
      context: .
      extra_hosts:
        - "example.com:X.X.X.X"
    extra_hosts:
      - "example.com:X.X.X.X"

Ah, pardon my ignorance. Not sure how you would do that.

Out of curiosity, why do you need it in the build context?

No problem.

I need this in the build context to be able to install dependencies that are on a private git server accessible only trought a vpn or via some whitelisted ips so i can’t the it’s ip direclty