NobleSiks
NobleSiks

Reputation: 369

Simple flask application with docker giving 404

I am trying to run a simple docker flask app. The app is inside the docker container. I have exposed the app to external clients bu making the host 0.0.0.0; yet, I am getting 404s. The server is definitely being reached, but the end points are not being available. I can't find the problem. I am new to docker, would appreciate some help.

#!/usr/bin/env python

import urlparse
import logging
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
import classify_nsfw
from flask import Flask


app = Flask(__name__) 


@app.route('/', methods=['GET']) 
def parse_from_url():
    return 'Hello world!'


# main driver function 
if __name__ == '__main__':  
    app.run(host='0.0.0.0')


Here is the dockerfile

FROM python:2.7
MAINTAINER [email protected]

RUN pip install --upgrade pip

RUN apt-get update && apt-get install -y --no-install-recommends \
        build-essential \
        cmake \
        git \
        wget \
        libatlas-base-dev \
        libboost-all-dev \
        libgflags-dev \
        libgoogle-glog-dev \
        libhdf5-serial-dev \
        libleveldb-dev \
        liblmdb-dev \
        libopencv-dev \
        libprotobuf-dev \
        libsnappy-dev \
        protobuf-compiler \
        python-dev \
        python-numpy \
        python-pip \
        python-scipy && \
    rm -rf /var/lib/apt/lists/*

ENV CAFFE_ROOT=/opt/caffe
WORKDIR $CAFFE_ROOT

# FIXME: clone a specific git tag and use ARG instead of ENV once DockerHub supports this.
ENV CLONE_TAG=master

RUN git clone -b ${CLONE_TAG} --depth 1 https://github.com/BVLC/caffe.git . && \
    for req in $(cat python/requirements.txt) pydot; do pip install $req; done && \
    mkdir build && cd build && \
    cmake -DCPU_ONLY=1 .. && \
    make -j"$(nproc)"

RUN pip install urllib3
RUN pip install http
RUN pip install httpserver
RUN pip install flask

ADD . /workspace/

ENV PYCAFFE_ROOT $CAFFE_ROOT/python
ENV PYTHONPATH $PYCAFFE_ROOT:$PYTHONPATH
ENV PATH $CAFFE_ROOT/build/tools:$PYCAFFE_ROOT:$PATH
RUN echo "$CAFFE_ROOT/build/lib" >> /etc/ld.so.conf.d/caffe.conf && ldconfig

ADD data_subset_rand /workspace/data_subset_rand

WORKDIR /workspace

Here is how I start the server:

docker run --rm -ti  -p 5000:5000 caffe:cpu  python server.py 5000

I get 404 for the route.

Flask output:

172.17.0.1 - - [22/Jan/2020 06:13:43] "GET / HTTP/1.1" 404 -

What am I doing wrong?

Upvotes: 0

Views: 1360

Answers (1)

NobleSiks
NobleSiks

Reputation: 369

Okay folks, don't make rookie errors like me. Rebuild for every change. It worked after re building the docker.

Upvotes: 1

Related Questions