Rahul Raghunath Rahul Raghunath - 1 year ago 156
Python Question

Issues with Running Flask and SQLAlchemy app through Docker

I have a web application written in python, sqlalchemy and flask.

The app along with static files, style sheets etc are stored in a folder called flask-app and the program is to be run from:

python server.py

When i run this from the terminal, it works perfectly well. But it doesn't work when i run it from docker.

My Dockerfile looks like this:

FROM ubuntu:latest
MAINTAINER Rahul Raghhunath "rahulraghu94@gmail.com"

RUN apt-get update -y
RUN apt-get install -y python-pip python3.5 build-essential

COPY . /server
WORKDIR /server

RUN pip install --upgrade pip
RUN pip install flask SQLAlchemy

ENTRYPOINT ["python3.5"]
CMD ["server.py"]

I'm running the following:

docker build -t rahulraghu94/wine-catalog .

It runs successfully.

But when i run:

docker run rahulraghu94/wine-catalog

It says that:

Traceback (most recent call last):
File "server.py", line 1, in <module>
from flask import Flask, render_template, request, url_for, redirect, flash, jsonify
ImportError: No module named 'flask'

I can't figure out what is going wrong. Any help?

Answer Source

flask is being installed for python 2.7x

as @polku suggested, try making use of pip3 if you wish to use the python3 interpreter

you may try installing python3-pip and using pip3 to install flask and SQLAlchemy

FROM ubuntu:latest

RUN apt-get update -y
RUN apt-get install -y python3-pip python3.5

COPY . /server
WORKDIR /server

RUN pip3 install flask SQLAlchemy

ENTRYPOINT ["python3.5"]
CMD ["server.py"]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download