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


CMD ["python", "/statics/js/"]

after running this command:

  • Linking containers with Mesos JSON file
  • PCI passthrough strategy in Docker or oVirt
  • Easiest way to deploy with docker-compose?
  • Docker instance port Management
  • Can't communicate with simple Docker Node.js web app
  • Error using Django with Docker - “Can't connect to MySQL server on '' (111)”)
  • docker run -it -p 8080:8080 -v
    ~/Development/my-Docker-builds/pythonReact/statics/:/statics/ -d

    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.

  • Docker for Windows can't reach the database in Windows 10 enterprise evaluation
  • Docker Swarm Mode: Not all VIPs for a service work. Getting timeouts for several VIPs
  • SSH Tunneling to docker container
  • Running docker command from docker container
  • docker compose not starting
  • How to downgrade Docker on Mac to 1.12.x or connect to 1.12 hosts from 1.13 in Mac?
  • 3 Solutions collect form web for “debugging containerised python web app”

    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/
    WORKDIR /statics/js
    EXPOSE 8080
    CMD ["python", "/app/"]

    3) Moved the non-static 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.


    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.

    You can use pdb to debug Python code in CLI. To achieve this, you just have to import pdb and call pdb.set_trace() where you would like to have a breakpoint in your Python code. Basically you have to insert the following line where you want a breakpoint:

    import pdb; pdb.set_trace()

    Then you have to run your Python code interactively.

    You could do that by running bash interactively in your container with

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

    and then running manually your app with

    root@5910f24d0d8a:/statics/js# python /statics/js/

    When the code will reach the breakpoint, it will pause and a prompt will be shown where you can type commands to inspect your execution.
    For more detail about the available commands, you can give a look at the pdb commands documentation.

    Also, I noted that you are building your image using the python:3.5-slim base image which is a (very) light Python image which does not include all is commonly included in a Python distribution.

    From the Python images page:

    This image does not contain the common packages contained in the default tag and only contains the minimal packages needed to run python. Unless you are working in an environment where only the python image will be deployed and you have space constraints, we highly recommend using the default image of this repository.

    Maybe using the standard python:3.5 image instead would solve your issue.

    As a quick tip for debugging containerized applications. If your application is failing with container crashed/stopped. Just launch the container image with CMD/ENTRYPOINT as /bin/bash then manually start the application once you have the container shell you can debug the application as per normal Linux system. CMD is straightforward to override as per ENTRYPOINT just use --entrypoint flag with docker run command.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.