pythondockerwsgidocker-containerturbogears2

debugging containerised python web app


I have made this first docker container, and it works as per the Dockerfile.

FROM python:3.5-slim

RUN apt-get update && \
    apt-get -y install gcc mono-mcs && \
        apt-get -y install vim && \
        apt-get -y install nano && \
            rm -rf /var/lib/apt/lists/*

RUN mkdir -p /statics/js

VOLUME ["/statics/"]

WORKDIR /statics/js

COPY requirements.txt /opt/requirements.txt

RUN pip install -r /opt/requirements.txt

EXPOSE 8080

CMD ["python", "/statics/js/app.py"]

after running this command:

docker run -it -p 8080:8080 -v ~/Development/my-Docker-builds/pythonReact/statics/:/statics/ -d ciasto/pythonreact:v2

and when I open the page localhost:8080 i get error:

A server error occurred.  Please contact the administrator.

but if I run this application normally, i.e. not containerised directly on my host machine: it works fine.

So I want to know what is causing server error. How do I debug a python app that runs via container to know what is causing it to not work. or what am I doing wrong.


Solution

  • Mainly, this:

    config.paths['static_files'] = 'statics'
    

    Should be:

    config.paths['static_files'] = '/statics'
    

    I've got your application up and running with your 'Hello World'

    Did these changes:

    1) The mentioned config.paths['static_files'] = '/statics'

    2) This Dockerfile (removed VOLUME)

    FROM python:3.5-slim
    
    RUN apt-get update && \
        apt-get -y install gcc mono-mcs && \
        apt-get -y install vim && \
        apt-get -y install nano && \
            rm -rf /var/lib/apt/lists/*
    
    COPY requirements.txt /opt/requirements.txt
    
    RUN pip install -r /opt/requirements.txt
    
    COPY ./statics/ /statics/
    COPY app.py /app/app.py
    WORKDIR /statics/js
    
    EXPOSE 8080
    
    CMD ["python", "/app/app.py"]
    

    3) Moved the non-static app.py to a proper place: root of the project.

    4) Run with: docker build . -t pyapp, then docker run -p 8080:8080 -it pyapp

    You should see Serving on port 8080... from terminal output. And Hello World in browser.

    I've forked your Github project and did a pull-request.


    Edit:

    If you need make changes when you develop, run the container with a volume to override the app that is packed in the image. For example:

    docker run -v ./static/js/:/static/js -p 8080:8080 -it pyapp
    

    You can have as many volumes as you want, but the app is already packed in the image and ready to push somewhere.