maverick maverick - 7 days ago 5
Python Question

Docker: how to see output/error of CMD [ "python", "./some_python.py" ]

I am using docker compose for multi-container setup for my project. For that I need some data in my mongodb image and I have created a python file for same. Now in the build process, I am only getting below message in the console and not any other stdout/sterr messages.

Step 12 : CMD python ./import_testdata.py
---> Running in 352b86106f68
---> fe091f22c2db


I have tried below options in my dockerfile

CMD ["/bin/sh", "-c", "python import_testdata.py > server.log 2>&1"]
CMD [ "python", "./import_testdata.py" ]


But I am not getting any success and also I couldn't see any error/output messages

See my Dockerfile at https://gist.github.com/dharmjit/a48ce2b6684b5a3f69a2056abca0b70b

Answer

The Docker Reference states: "There can only be one CMD instruction in a Dockerfile. If you list more than one CMD then only the last CMD will take effect." (https://docs.docker.com/engine/reference/builder/)

Why don't you perform your actions with a RUN instruction?

Comments