Reputation: 31
I would like some input on podman-compose
and podman
(I tried with docker
and docker-compose
with the same result) regarding environment variables, please consider the following scenario:
I've a binary file my-binary
in /tmp/my-binaries
:
#!/bin/sh
echo "Hello World"
I've created a docker-compose.yml
:
version: "3"
services:
test-container:
image: python:3.9-slim
environment:
- PATH="/home/minkiu/.local/bin:/home/minkiu/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/minkiu/.pyenv/bin:/tmp/my_binaries"
volumes:
- "/tmp/my_binaries:/tmp/my_binaries"
command: ["my-binary"]
where I am trying to append to PATH
the directory where I have my binaries and map it with the volumes
key.
Now my expectation is that upon podman-compose up
this I should see Hello World
, but that's not the case, I get:
Error: unable to start container <container-id>: executable file `my-binary` not found in $PATH: No such file or directory: OCI runtime attempted to invoke a command that was not found
125
By default podman-compose
's output is quite verbose, so I can see the command:
podman create --name=podman-test_test-container_1 --pod=podman-test --label io.podman.compose.config-hash=123 --label io.podman.compose.project=podman-test --label io.podman.compose.version=0.0.1 --label com.docker.compose.container-number=1 --label com.docker.compose.service=test-container -e PATH="/home/minkiu/.local/bin:/home/minkiu/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/minkiu/.pyenv/bin:/tmp/my_binaries" -v /tmp/my_binaries:/tmp/my_binaries --add-host test-container:127.0.0.1 --add-host podman-test_test-container_1:127.0.0.1 python:3.9-slim my-binary
So I grab the same command, and perform a podman run
:
podman run --rm -e PATH="/home/minkiu/.local/bin:/home/minkiu/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/minkiu/.pyenv/bin:/tmp/my_binaries" -v /tmp/my_binaries:/tmp/my_binaries python:3.9-slim my-binary
And I get the expected output.
Some research made me aware that run
is create, start and attach
all in one.
So my question is, why is not working through the podman-compose
and it is through podman run
?
Is podman run
really something more than just podman {create,start,attach}
?
Cheers.
Upvotes: 2
Views: 2907
Reputation: 2310
I got the same issue you described which in my environment is related to the SELinux configuration. So I solved the problem with an estra :Z
in volumes
:
version: "3"
services:
test-container:
image: python:3.9-slim
environment:
- PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/tmp/my_binaries"
volumes:
- /tmp/my_binaries:/tmp/my_binaries:Z
command: ["/tmp/my_binaries/my-binary"]
The script /tmp/my_binaries/my-binary
must be executable. If not the following error will be displayed:
open executable: Permission denied: OCI permission denied
Here's the full output:
$ podman-compose up
using podman version: podman version 3.4.1
podman pod create --name=tests --share net
8739e69897f2b7c7d004c7ea83df3b3a5fd22db6533720bfd6bffcd0040d651e
0
podman create --name=tests_test-container_1 --pod=tests --label io.podman.compose.config-hash=123 --label io.podman.compose.project=tests --label io.podman.compose.version=0.0.1 --label com.docker.compose.container-number=1 --label com.docker.compose.service=test-container -e PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/tmp/my_binaries" -v /tmp/my_binaries:/tmp/my_binaries:Z --add-host test-container:127.0.0.1 --add-host tests_test-container_1:127.0.0.1 python:3.9-slim /tmp/my_binaries/my-binary
6560b3335990700d0cec69a103404cadab52bbfd436e90347032bb6716265e94
0
podman start -a tests_test-container_1
Hello World
0
Upvotes: 1