Skip to content

extra_hosts doesnt add the entry to podman build command #1366

@Athishpranav2003

Description

@Athishpranav2003

Describe the bug
Adding extra_hosts entry in the compose file doesnt add add-hosts argument to the podman build command. This is needed to add DNS entry for image build.

To Reproduce
Steps to reproduce the behavior:
docker-compose.yml

version: "3.9"

services:
  curl-test:
    build:
      context: .
      extra_hosts:
      - "example.internal:103.158.42.45"
    container_name: curl-extra-hosts-test
    extra_hosts:
      - "example.internal:103.158.42.45"
    command: >
      sh -c "
      echo 'Curling example.internal...' &&
      curl -I http://example.internal &&
      sleep 3600
      "

Dockerfile

FROM alpine:latest

RUN apk add --no-cache curl


RUN curl -I http://example.internal

CMD ["sh"]

Expected behavior
Both curl in image building step and the shell command inside container should succeed

Actual behavior
Fails to resolve the host

Output

$ podman-compose up --build 
STEP 1/4: FROM alpine:latest
STEP 2/4: RUN apk add --no-cache curl
--> Using cache ce7be49ed5301fe28652e1c9e8cb6639b0823c15a83b03df5673a4671e78fac1
--> ce7be49ed530
STEP 3/4: RUN curl -I http://example.internal
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0   0     0   0     0     0     0  --:--:-- --:--:-- --:--:--     0curl: (6) Could not resolve host: example.internal (Domain name not found)
Error: building at STEP "RUN curl -I http://example.internal": while running runtime: exit status 6
ERROR:podman_compose:Build command failed
$ docker compose up --build
WARN[0000] /home/aggressive_racer1/projects/test-podman/docker-compose.yaml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
[+] Building 0.5s (9/9) FINISHED                                                                                                    
 => [internal] load local bake definitions                                                                                     0.0s
 => => reading from stdin 636B                                                                                                 0.0s
 => [internal] load build definition from Dockerfile                                                                           0.0s
 => => transferring dockerfile: 194B                                                                                           0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                               0.4s
 => [internal] load .dockerignore                                                                                              0.0s
 => => transferring context: 2B                                                                                                0.0s
 => [1/3] FROM docker.io/library/alpine:latest@sha256:865b95f46d98cf867a156fe4a135ad3fe50d2056aa3f25ed31662dff6da4eb62         0.0s
 => CACHED [2/3] RUN apk add --no-cache curl                                                                                   0.0s
 => CACHED [3/3] RUN curl -I http://example.internal                                                                           0.0s
 => exporting to image                                                                                                         0.0s
 => => exporting layers                                                                                                        0.0s
 => => writing image sha256:e7e8ae82735aa7af89378848998fb7f50bc8ff1f992910fa748bcfd45b24628f                                   0.0s
 => => naming to docker.io/library/test-podman-curl-test                                                                       0.0s
 => resolving provenance for metadata file                                                                                     0.0s
[+] up 1/1
 ✔ Image test-podman-curl-test Built                                                                                           0.5s 
Attaching to curl-extra-hosts-test
curl-extra-hosts-test  | Curling example.internal...
curl-extra-hosts-test  |   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
curl-extra-hosts-test  |                                  Dload  Upload   Total   Spent    Left  Speed
curl-extra-hosts-test  | HTTP/1.0 302 Redirect
  0     0   0     0   0     0     0     0  --:--:-- --:--:-- --:--:--     0
curl-extra-hosts-test  | Connection: Close
curl-extra-hosts-test  | Location: https://example.internal/
curl-extra-hosts-test  | 
...

Environment:

  • OS: Fedora Linux 42 (Workstation Edition)
  • podman version: 5.5.0
  • podman compose version: 1.5.0 (f7eeda1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions