I'm attempting to deploy a flask web app using a docker container. I'm dockerizing the app because I have a package (RDKit) which cannot be pip installed and must be done using conda.
When using
docker run my_image
I get an import error for flask - the first library that my python script imports. However, I'm able to deploy the app locally when I specify the port using the command: docker run -p 80:80 my_image
. I have a feeling that my Dockerfile might be the problem:
FROM cameroncruz/flask-nginx-uwsgi-miniconda:python3.6
# Create conda env (base image is built on python 3.6 and will have to migrate to 3.7 later)
RUN conda create --name myenv python=3.6
# Install the required dependencies
RUN /bin/bash -c ". activate myenv && \
conda config --add channels conda-forge && \
conda install -y \
scikit-learn \
numpy \
scipy \
rdkit \
wtforms \
ipython \
flask \
uwsgi"
# Copy custom supervisor config
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
# Copy application files
# The application to be served
COPY server/main.py /app/main.py
# Folder containing the styling
COPY server/static/ /app/static
# Folder containing the html
COPY server/templates/ /app/templates
# The trained machine learning model
copy server/model.pkl /app/model.pkl
# EXPOSE PORT 80
EXPOSE 80
# Run app.py when the container launches
CMD ["python", "main.py"]
The beginning of my python code:
from flask import Flask, jsonify, request, json
The end of my python code:
app.run(debug=False, host='0.0.0.0', port=80)
Here is the supervisord.conf file:
nodaemon=true
[program:uwsgi]
environment=PATH='/opt/conda/envs/myenv/bin'
command=/opt/conda/envs/myenv/bin/uwsgi --ini /etc/uwsgi/uwsgi.ini --die-on-term --need-app
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:nginx]
command=/usr/sbin/nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
# Graceful stop, see http://nginx.org/en/docs/control.html
stopsignal=QUIT
I have deployed apps on Azure before but this is my first time with a container. I'm also using Ubuntu 18.04, if that matters. Any and all help is appreciated, thank you!