简体   繁体   中英

Running a Flask app within a Docker container results in “./boot.sh: 2: exec: gunicorn: not found”

I am trying to create a Flask app running within a Docker container but I have some complex dependencies so I am building from this image https://hub.docker.com/r/continuumio/anaconda/ .

I build the image (goes fine... environment works...) :

docker build -t my_image:latest .

Then try to run it

docker run --name my_image -p 80:5000 --rm my_image:latest

I get this error:

./boot.sh: 2: exec: gunicorn: not found

Here is my directory I am building from:

my_template
--api.py
--boot.sh
--environment.yml
--Dockerfile

I have a very simple flask app. api.py

from flask import Flask, jsonify
app = Flask(__name__)

@app.route('/', methods=['GET'])
def hello_world():
    return jsonify({'message': 'Hello World'})

@app.route('/test', methods=['GET'])
def test():
    return jsonify({'test': 'test'})

if __name__ == "__main__":
    app.run(debug=True) # remember to set debug to False

environment.yml is as follows:

name: ox
channels:
  - conda-forge
  - defaults
dependencies:
  {---OMITTED FOR BREVITY---}
prefix: /home/me/anaconda3/envs/ox

Dockerfile is as follows:

FROM continuumio/miniconda:latest

WORKDIR /home/conda_flask_docker

COPY environment.yml ./
COPY api.py ./
COPY boot.sh ./

RUN chmod +x boot.sh

RUN conda env create -f environment.yml

RUN echo "source activate ox" > ~/.bashrc
ENV PATH /opt/conda/envs/ox/bin:$PATH

EXPOSE 5000

ENTRYPOINT ["./boot.sh"]

And... boot.sh

#!/bin/sh
exec gunicorn -b :5000 --access-logfile - --error-logfile - api:app

Solved this on my own...

I needed to add

 - flask=1.1.2=pyh9f0ad1d_0 
 - gunicorn=20.0.4=py38h32f6830_1 

to the dependencies section of environment.yml. I had used conda env export > environment.yml to build my environment.yml BEFORE I had added Flask and gunicorn.

If that doesn't do it, adding gunicorn via RUN command in the Dockerfile should do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM