-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Issue Description
When creating a container via the Docker API (like Podman Desktop does), if the Healthcheck.Test array contains an argument that itself has spaces (like ["CMD", "/usr/bin/mysql", "--protocol=TCP", "--execute=SELECT 1;"]), Podman splits this argument into multiple arguments ([..., "--execute=SELECT", "1;"]). This is inconsistent with Docker's behavior.
I think the issue is caused by how "CMD" HealthCheck.Test arrays are parsed into a string and then turned back into an array before execution.
In the container creation handler, the Healthcheck.Test array from the JSON payload is concatenated into a single, space-separated string.
podman/pkg/api/handlers/compat/containers_create.go
Lines 611 to 632 in 683e9b2
| if cc.Config.Healthcheck != nil { | |
| finCmd := "" | |
| for _, str := range cc.Config.Healthcheck.Test { | |
| finCmd = finCmd + str + " " | |
| } | |
| if len(finCmd) > 1 { | |
| finCmd = finCmd[:len(finCmd)-1] | |
| } | |
| cliOpts.HealthCmd = finCmd | |
| if cc.Config.Healthcheck.Interval > 0 { | |
| cliOpts.HealthInterval = cc.Config.Healthcheck.Interval.String() | |
| } | |
| if cc.Config.Healthcheck.Retries > 0 { | |
| cliOpts.HealthRetries = uint(cc.Config.Healthcheck.Retries) | |
| } | |
| if cc.Config.Healthcheck.StartPeriod > 0 { | |
| cliOpts.HealthStartPeriod = cc.Config.Healthcheck.StartPeriod.String() | |
| } | |
| if cc.Config.Healthcheck.Timeout > 0 { | |
| cliOpts.HealthTimeout = cc.Config.Healthcheck.Timeout.String() | |
| } | |
| } |
This single string is then passed down to MakeHealthCheckFromCli in pkg/specgenutil/specgen.go. Inside this function, the string is split back into an array using strings.Fields, which splits on any whitespace.
podman/pkg/specgenutil/specgen.go
Lines 960 to 975 in 683e9b2
| func MakeHealthCheckFromCli(inCmd, interval string, retries uint, timeout, startPeriod string, isStartup bool) (*manifest.Schema2HealthConfig, error) { | |
| cmdArr := []string{} | |
| isArr := true | |
| err := json.Unmarshal([]byte(inCmd), &cmdArr) // array unmarshalling | |
| if err != nil { | |
| cmdArr = strings.SplitN(inCmd, " ", 2) // default for compat | |
| isArr = false | |
| } | |
| // Every healthcheck requires a command | |
| if len(cmdArr) == 0 { | |
| return nil, errors.New("must define a healthcheck command for all healthchecks") | |
| } | |
| var concat string | |
| if strings.ToUpper(cmdArr[0]) == define.HealthConfigTestCmd || strings.ToUpper(cmdArr[0]) == define.HealthConfigTestNone { // this is for compat, we are already split properly for most compat cases | |
| cmdArr = strings.Fields(inCmd) |
This will cause any arguments containing spaces to be treated as separate arguments.
Steps to reproduce the issue
Create a minimal container with a healthcheck containing a space
curl -X POST "http://localhost/containers/create?name=healthcheck-test" \
-H "Content-Type: application/json" \
--unix-socket ~/.local/share/containers/podman/machine/podman.sock \
-d '{
"Image": "mysql:latest",
"Healthcheck": {
"Test": ["CMD", "/usr/bin/mysql", "--protocol=TCP", "--execute=SELECT 1;"]
}
}'Describe the results you received
Inspect the container's spec
jq '.Config.Healthcheck' \
<(curl -s "http://localhost/containers/healthcheck-test/json" --unix-socket ~/.local/share/containers/podman/machine/podman.sock){
"Test": [
"CMD",
"/usr/bin/mysql",
"--protocol=TCP",
"--execute=SELECT",
"1;"
],
"Interval": 1000000000,
"Timeout": 5000000000,
"Retries": 5
}Describe the results you expected
Here is the output of inspecting the same container created using Docker
jq '.Config.Healthcheck' \
<(curl -s "http://localhost/containers/healthcheck-test/json" --unix-socket /var/run/docker.sock){
"Test": [
"CMD",
"/usr/bin/mysql",
"--protocol=TCP",
"--execute=SELECT 1;"
],
"Interval": 1000000000,
"Timeout": 5000000000,
"Retries": 5
}podman info output
Client:
APIVersion: 5.5.1
BuildOrigin: pkginstaller
Built: 1749159952
BuiltTime: Thu Jun 5 23:45:52 2025
GitCommit: 850db76dd78a0641eddb9ee19ee6f60d2c59bcfa
GoVersion: go1.24.3
Os: darwin
OsArch: darwin/arm64
Version: 5.5.1
host:
arch: arm64
buildahVersion: 1.40.1
cgroupControllers:
- cpu
- io
- memory
- pids
cgroupManager: systemd
cgroupVersion: v2
conmon:
package: conmon-2.1.12-3.fc41.aarch64
path: /usr/bin/conmon
version: 'conmon version 2.1.12, commit: '
cpuUtilization:
idlePercent: 99.45
systemPercent: 0.26
userPercent: 0.29
cpus: 12
databaseBackend: sqlite
distribution:
distribution: fedora
variant: coreos
version: "41"
eventLogger: journald
freeLocks: 2043
hostname: localhost.localdomain
idMappings:
gidmap:
- container_id: 0
host_id: 1000
size: 1
- container_id: 1
host_id: 100000
size: 1000000
uidmap:
- container_id: 0
host_id: 502
size: 1
- container_id: 1
host_id: 100000
size: 1000000
kernel: 6.12.13-200.fc41.aarch64
linkmode: dynamic
logDriver: journald
memFree: 18904375296
memTotal: 23395192832
networkBackend: netavark
networkBackendInfo:
backend: netavark
dns:
package: aardvark-dns-1.15.0-1.fc41.aarch64
path: /usr/libexec/podman/aardvark-dns
version: aardvark-dns 1.15.0
package: netavark-1.15.2-1.fc41.aarch64
path: /usr/libexec/podman/netavark
version: netavark 1.15.2
ociRuntime:
name: crun
package: crun-1.20-2.fc41.aarch64
path: /usr/bin/crun
version: |-
crun version 1.20
commit: 9c9a76ac11994701dd666c4f0b869ceffb599a66
rundir: /run/user/502/crun
spec: 1.0.0
+SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
os: linux
pasta:
executable: /usr/bin/pasta
package: passt-0^20250121.g4f2c8e7-2.fc41.aarch64
version: |
pasta 0^20250121.g4f2c8e7-2.fc41.aarch64-pasta
Copyright Red Hat
GNU General Public License, version 2 or later
<https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
remoteSocket:
exists: true
path: unix:///run/user/502/podman/podman.sock
rootlessNetworkCmd: pasta
security:
apparmorEnabled: false
capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
rootless: true
seccompEnabled: true
seccompProfilePath: /usr/share/containers/seccomp.json
selinuxEnabled: true
serviceIsRemote: true
slirp4netns:
executable: /usr/bin/slirp4netns
package: slirp4netns-1.3.1-1.fc41.aarch64
version: |-
slirp4netns version 1.3.1
commit: e5e368c4f5db6ae75c2fce786e31eef9da6bf236
libslirp: 4.8.0
SLIRP_CONFIG_VERSION_MAX: 5
libseccomp: 2.5.5
swapFree: 0
swapTotal: 0
uptime: 8h 20m 55.00s (Approximately 0.33 days)
variant: v8
plugins:
authorization: null
log:
- k8s-file
- none
- passthrough
- journald
network:
- bridge
- macvlan
- ipvlan
volume:
- local
registries:
search:
- docker.io
store:
configFile: /var/home/core/.config/containers/storage.conf
containerStore:
number: 3
paused: 0
running: 1
stopped: 2
graphDriverName: overlay
graphOptions: {}
graphRoot: /var/home/core/.local/share/containers/storage
graphRootAllocated: 98899800064
graphRootUsed: 16771616768
graphStatus:
Backing Filesystem: xfs
Native Overlay Diff: "true"
Supports d_type: "true"
Supports shifting: "false"
Supports volatile: "true"
Using metacopy: "false"
imageCopyTmpDir: /var/tmp
imageStore:
number: 3
runRoot: /run/user/502/containers
transientStore: false
volumePath: /var/home/core/.local/share/containers/storage/volumes
version:
APIVersion: 5.5.1
BuildOrigin: 'Copr: packit/containers-podman-26294'
Built: 1749081600
BuiltTime: Thu Jun 5 02:00:00 2025
GitCommit: 850db76dd78a0641eddb9ee19ee6f60d2c59bcfa
GoVersion: go1.23.9
Os: linux
OsArch: linux/arm64
Version: 5.5.1Podman in a container
No
Privileged Or Rootless
Rootless
Upstream Latest Release
No
Additional environment details
No response
Additional information
No response