Merge pull request #26202 from Luap99/compat-base-hosts

compat API: respect base_hosts_file containers.conf option
This commit is contained in:
openshift-merge-bot[bot] 2025-05-27 13:40:23 +00:00 committed by GitHub
commit d667e2fe51
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 2 deletions

View File

@ -120,8 +120,10 @@ func CreateContainer(w http.ResponseWriter, r *http.Request) {
// moby always create the working directory
localTrue := true
sg.CreateWorkingDir = &localTrue
// moby doesn't inherit /etc/hosts from host
sg.BaseHostsFile = "none"
// moby doesn't inherit /etc/hosts from host, but only overwrite if not set in containers.conf
if rtc.Containers.BaseHostsFile == "" {
sg.BaseHostsFile = "none"
}
ic := abi.ContainerEngine{Libpod: runtime}
report, err := ic.ContainerCreate(r.Context(), sg)

View File

@ -677,6 +677,35 @@ for endpoint in containers/create libpod/containers/create; do
done
stop_service
# Create a temporary containers.conf with custom base_hosts_file set
testdir=$(mktemp -d)
cat > $testdir/containers.base_hosts_file.conf <<EOF
[containers]
base_hosts_file = "$testdir/hosts"
EOF
cat > $testdir/hosts <<EOF
10.0.0.2 testname
192.168.1.1 abc
EOF
CONTAINERS_CONF_OVERRIDE=$testdir/containers.base_hosts_file.conf start_service
t POST containers/create \
Image=$IMAGE \
Cmd='["cat","/etc/hosts"]' \
Tty=true \
201 \
.Id~[0-9a-f]\\{64\\}
cid=$(jq -r '.Id' <<<"$output")
t POST containers/${cid}/start 204
t GET "containers/${cid}/logs?follow=true&stdout=true&stderr=true" 200
like "$(<$WORKDIR/curl.result.out)" ".*10.0.0.2[[:space:]]testname.*192.168.1.1[[:space:]]abc.*" "contains containers.conf base_hosts_file hosts"
stop_service
rm -rf "$testdir"
start_service
# Our states are different from Docker's.