Brian C
Brian C

Reputation: 1437

Building Docker image for a python flask web app. Image does not appear or requirements.txt not found

I am trying to create a build of a webapp I have created using Docker, but I have had no success. I've tried to follow two different tutorials but neither worked for me

Following Tutorial 1: The build seemed to complete without any problems but I could not find the image file anywhere, and 'sudo docker ps -a' returned nothing.

Following through thtutorial 2: I am now getting another error, that the requirements file is not found. I looked up solutions to that here, but it seems I am doing the correct thing by adding it to the build with the 'ADD requirements.txt /webapp' command. I checked that I spelled requirements right, haha. Now I do see it in 'sudo docker ps -a', but I dont see any image file and presumably it would not work if I did, since it could not find the requirements.

I'm quite confused as to what is wrong and how I should properly build a docker. How to I get it to find the requirements file, and then upon completing the "Build" command, actually have an image. Where is this image stored?

Below is the setup I have after following the second tutorial.

Dockerfile

FROM ubuntu:latest

#Update OS
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade

# Install Python
RUN apt-get install -y python-dev python-pip

# Add requirements.txt
ADD requirements.txt /webapp

# Install uwsgi Python web server
RUN pip install uwsgi

# Install app requirements
RUN pip install -r requirements.txt

# Create app directory
ADD . /webapp

# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp

# Expose port 8000 for uwsgi
EXPOSE 8000


ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
CMD ["app.py"]

Requirements

Flask==0.12.1
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.11.5
SQLite3==3.18.0

Directory Structure (if it matters)

app.py
image_data.db
README.txt
requirements.txt
Dockerfile
templates
 - index.html
static/
 - image.js
 - main.css
 img/
   - camera.png
 images/
   - empty

Current output of ' sudo docker ps -a'

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS                      PORTS               NAMES
663d4e096938        8f5126108354        "/bin/sh -c 'pip i..."   17 minutes ago      Exited (1) 17 minutes ago                       admiring_agnesi

Upvotes: 1

Views: 587

Answers (1)

salehinejad
salehinejad

Reputation: 7368

The requirements.txt should be in the same directory as your dockerfile exists. I see from the dockerfile that the requirements.txt is added to webapp but the

RUN pip install -r requirements.txt

is trying to find it in the current directory; You probably need to copy rquirement.txt to the current directory like

ADD requirements.txt .

Lets see if that works. I did not test it.

You can see the images by

docker images 

and then run it like

docker run -t image_name

Upvotes: 2

Related Questions