My Dockerfile looks like follows;
FROM python:2.7 COPY . /temp WORKDIR /temp CMD ["python", "app.py", "100"] My Python file looks like this,
import sys print "This is the name of the script: ", sys.argv[0] print "Number of arguments: ", len(sys.argv) print "The arguments are: " , str(sys.argv) file = open("log.log", "a") x = int(sys.argv[1]) print "received value of x is: ", x if x < 100: file.write('entered value is less than 100: Exiting with exit code 0; SUCEESS') elif x == 100: file.write('entered value is equal to 100: Exiting with exit code 1; SUCEESS') else: file.write('entered value is more than 100: Exiting with exit code 2; FAILED') The way I build this container is as follows: docker build python-container .
The way I run the container is as follows: docker run -v ~/logs/:app python-container
What I want is to mount the container directory in which log in generated to my host so that the log file generated by the python is available on my host computer.
But unfortunately, this is not happening,
Debug done by me:
I initially used the python in ENTRYPOINT but it seems the commands in ENTRYPOINT are compressed and bundled in the container and then the container is mounted and thus it failed.
I kept the container running forever by using the
ENTRYPOINT ["tail", "-f", "/dev/null"]but still it failed.I also used docket volumes, created volumes, mounted them and then run the containers and still the log is not available outside.
My question here is what am I missing?
Ultimately, my aim is to have different containers running different python jobs and generating different log files in a specific directory on my host...
I would really appreciate any help in this matter...