Hello Team,
I have followed the instructions to create a docker image file as mentioned in the lecture:
- Created a docker file
- Added instructions in the docker file
- Created an image of the application(in this case my-simple-webapp)
- I could see the image upon executing the command ‘docker run images’
However, while trying to run the newly created image my-simple-webapp, I am facing an issue as shown below
Could you please help if I am missing something?
Regards
Sudheer
Hi @sudhir560
Please post the Dockerfile.
Put it inside a code block like this
Not a screenshot.
Thanks
Hello @Alistair_KodeKloud
Here is the docker file i used:
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip install flask
COPY app.py opt/app.py
ENTRYPOINT FLASK_APP = app.py flask run --host = 0.0.0.0
Let me know if anything else is required.
Regards
Sudheer
Try this
FROM ubuntu
RUN apt-get update
RUN apt-get install -y python3 python3-pip
RUN pip install flask
COPY app.py /opt/app.py
ENV FLASK_APP=app
WORKDIR /opt
ENTRYPOINT ["flask", "run", "--host=0.0.0.0" ]
You can also debug inside the container if it doesn’t successfully start by running the image to a command prompt and running flask from the command line until you get the right arguments - then rebuild the image again…
docker run -it --rm --entrypoint /bin/sh my-simple-webapp
Things to note with this.
- Set the
FLASK_APP
environment variable with the ENV
command
-
FLASK_APP
defaults to .py
, hence only need to specify app
-
ENTRYPOINT
is a JSON array of the command and its arguments
-
WORKDIR
sets the default directory in the container.
Thank you @Alistair_KodeKloud. This helped.
I am now able to run the application from the image.
Regards
Sudheer