Home > Software design >  python -c as a docker entrypoint
python -c as a docker entrypoint

Time:11-01

I am trying to test a docker container in my CI/CD pipeline by running a small piece of python code. What I was hoping would work is something like this:

docker run --entrypoint "python3 -c" image-name "import os;..."

However I get error, even if I replace python3 with python

docker: Error response from daemon: OCI runtime create failed: container_linux.go:380: starting container process caused: exec: "python3 -c": executable file not found in $PATH: unknown.

Right now I create a script during runtime and mount it using volume

docker run --entrypoint "python3" -v /tmp/testing/script.py:/testscript.py image-name script.py

Is there any way how to make python3 -c work in similar manner to my current solution? Or how would you perform a simple test which involves running a container and running some simple python code inside?
EDIT: I have /bin/bash entrypoint running a sh script in my dockerfile, I am trying to override this.

CodePudding user response:

You can specify the whole command at the end, would the following work for you?

docker run \
python:alpine \
python -c "import time; print('sleeping for 3 secs'); time.sleep(3); print('done sleeping')"

CodePudding user response:

After seeing @jabsson's answer I was able to come up with this

docker run --rm --entrypoint "python" image-name -c "print('hello')"

which does exactly what I needed. Thank you for the idea

  • Related