I'd like to pass a variable to podman's CMD
when starting the container. However, the variable ends up undefined.
Minimal image:
FROM alpine:latest
CMD ["sh", "-c", "echo", "$VAR"]
Running this minimal image with
podman run -e VAR=0 minimal-image
only returns an empty string and not the expected 0. From within the container VAR
holds the value of 0 as I would expect.
podman run -it -e VAR=0 minimal-image sh
# inside container:
echo $VAR
0
The argument after "-c" should contain the full command.
In other words, replace
CMD ["sh", "-c", "echo", "$VAR"]
with
CMD ["sh", "-c", "echo $VAR"]
Demo:
$ cat Dockerfile
FROM alpine:latest
CMD ["sh", "-c", "echo $VAR"]
$ podman build -q -t test .
4a09e7eb28f0e40cd903cbf653b71a1265fce67e07f9cba5ab6f38719fe27a03
$ podman run -e VAR=0 localhost/test
0
$