containers / containers/podman-py

ImagesManager.build extra_hosts argument not working

Open
#398 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
381
Forks
140
Avg merge
5h 30m
Merged PRs (30d)
1

Description

I am trying to pass extra_hosts argument to build without success.

Bellow is a simple way to reproduce this issue:
```
import podman
from podman import PodmanClient

CONTAINER_SOCKET_PATH = "unix:///var/run/docker.sock"

# Initialize the Podman client
client = PodmanClient(base_url=CONTAINER_SOCKET_PATH)

# Specify the path to your Dockerfile and context directory
dockerfile_path = "Dockerfile"
# context_path = '/path/to/your/context'

# Build the image
image, logs = client.images.build(
path="/private/tmp/tmp",
dockerfile=dockerfile_path,
tag="myimage:latest", # Replace with your desired image tag
rm=True, # Optional: Remove intermediate containers after build
extra_hosts={"example.com": "192.168.1.1"},
)

# Optionally, you can inspect the built image
print(f"Built image ID: {image.id}")
```

Without the extra_hosts argument, the code works fine.
With the extra_hosts argument I get:

```
podman.errors.exceptions.APIError: 400 Client Error: Bad Request (failed to parse query parameter 'extrahosts': "{\"repo\": \"147.204.144.142\"}": json: cannot unmarshal object into Go value of type []string)
```

Using the CLI also works:
```
podman buildx build --add-host=repo:147.204.144.142 --build-arg PACKAGE=mypackage --platform linux/amd64 -t s3loadtest .
```

Contributor guide

Open the contributing guide

Research direction

Start at the client.images.build entry point and trace how extra_hosts becomes the API's extrahosts query parameter. Reproduce the example, compare its request with the working CLI --add-host form, and consider the issue done when the Python call accepts the host mapping without the API parse error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.