I am working on a django docker image and I want to execute a function ussing command line, I know that I can enter to shell python docker container and run a function like this :
docker container lsto find the container id and use in the next commanddocker container exec -it <container_id> python3 manage.py shellThen:
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>>
>>> from xx import foo
>>> foo() # foo() has been excecuted
However, i was wondering if i can use something similar like python flag -c which help to run small piece of python code as command line like this:
python3 -c "from xx import foo; foo()"
I tried to insert a cmd with linux tubes :
echo 'from xx import foo; foo()' | docker container exec -it <container_id> python3 manage.py shell, However it doesn't work.
I'd appreciate any advice, thanks for your time.