Docker container fails to run, Error : python3: can't open file 'flask run --host=0.0.0.0': [Errno 2] No such file or directory Docker container fails to run, Error : python3: can't open file 'flask run --host=0.0.0.0': [Errno 2] No such file or directory flask flask

Docker container fails to run, Error : python3: can't open file 'flask run --host=0.0.0.0': [Errno 2] No such file or directory


The best use for ENTRYPOINT is to set the image’s main command,allowing that image to be run as though it was that command (and thenuse CMD as the default flags).

https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint

lots of people seem to miss this point about the ENTRYPOINT and CMD Dockerfile-instructions.

the ENTRYPOINT instruction supposed to run some executable, which should run every time you start the container, such as starting your server.

the CMD supposed to include the flags provided to that executable, so they can be easily overridden when running the container.

i am not sure you are supposed to have more then one CMD instruction. if you need to run commands during the build process, you can use the RUN instruction - for example:

RUN mkdir some/dir

now:

run.py is the main python flask file for execution

hence i suggest you define it as your entrypoint:

ENTRYPOINT [ "./run.py" ]

commands that you may also want to run every time the container starts, such as flask run --host=0.0.0.0 you can:

  • move that command to sit inside the run.py file

    or

  • keep the CMD [ "flask", "run", "--host=0.0.0.0" ] line. this command will be passed as an argument to the run.py entrypoint, so you may execute it in there. that way you can easily override the command when running the container with alternative arguments.

this stuff is also in the docs:

Understand how CMD and ENTRYPOINT interact

Both CMD and ENTRYPOINTinstructions define what command gets executed when running acontainer. There are few rules that describe their co-operation.

Dockerfile should specify at least one of CMD or ENTRYPOINT commands.

ENTRYPOINT should be defined when using the container as anexecutable.

CMD should be used as a way of defining default arguments for anENTRYPOINT command or for executing an ad-hoc command in a container.

CMD will be overridden when running the container with alternativearguments.