Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

981
Views
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

I am new to docker and I am trying to dockerize a python flask microservice. The docker file builds successfully but on running the container it gives an error :

python3: can't open file 'flask': [Errno 2] No such file or directory

I am assuming there is some mistake in my docker file either in the COPY path, ENTRYPOINT or CMD i.e. the commands that I use to run the flask application. I am not able to figure out the mistake.

The directory structure on Ubuntu machine is:

/home/ubuntu/Docker/auth

The directory auth contains my Dockerfile and all other python flask files:

$ls 
Dockerfile   run.py    views.py     resources.py    models.py

run.py is the main python flask file for execution. I'm sure there is some syntax error in how I am executing the CMD command for the flask application and it is not able to find run.py for execution. I am not able to correct that error.

The image builds successfully. For running the container I use:

docker build <imageid>

Dockerfile

FROM ubuntu:16.04

MAINTAINER xyz <xyz@yahoo.com>

RUN apt-get update \
    && apt-get install -y software-properties-common vim \
    && add-apt-repository ppa:jonathonf/python-3.6 \
    && apt-get update -y \
    && apt-get install -y build-essential python3.6 python3.6-dev python3-pip 
       python3.6-venv \
    && pip3 install --upgrade pip

WORKDIR /auth
COPY . /auth

RUN pip3 install alembic==0.9.9 \
    && pip3 install Flask==1.0.2 \

ENTRYPOINT [ "python3" ]
CMD [ "export","FLASK_APP=run.py" ]
CMD [ "set", "FLASK_APP=run.py" ]
CMD [ "flask", "run", "--host=0.0.0.0" ]

Expected: Application should run on the container. Actual: Python3: can't open file 'flask': [Errno 2] No such file or directory

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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 then use 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 ENTRYPOINT instructions define what command gets executed when running a container. 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 an executable.

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

CMD will be overridden when running the container with alternative arguments.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!