简体   繁体   中英

Flask App runs in terminal but not in Docker Container

So, I've got this flask app that works fine when I run it via the terminal, but for some reason, if I start up a docker container, it instantly exits with 'exit code zero'.

Here is the folder structure: https://imgur.com/a/BOGCt6S

docker-compose.yml:

version: '3.2'

services:

    flask-app:
        build: ./Flask_App
        volumes:
            - ./Flask_App/static:/Flask_App/static
            - ./Flask_App/db:/Flask_App/db
        ports:
            - '5001:5001'
        # restart: unless-stopped

Dockerfile:

FROM python:3

# Setup env
COPY requirements.txt ./

RUN pip install -r requirements.txt

# Setup App
RUN mkdir -p /Flask_App

COPY . /Flask_App

WORKDIR /Flask_App

EXPOSE 5001

ENTRYPOINT [ 'python3' ]

CMD [ 'app.py' ]

and the app.py file: (I know its just imports, but it works fine when I run it via the terminal on the host, so it probably is working ok)

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_login import LoginManager
from flask_bootstrap import Bootstrap

from forms import *

app = Flask(__name__)
app.config.from_pyfile('config.py')
Bootstrap(app)

db = SQLAlchemy(app)

login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'

from views import *

if __name__ == '__main__':
    app.run(host=app.config['HOST'], port=app.config['PORT'], debug=app.config['DEBUG'])

and just in case, here is a part of the 'config.py' file:

DEBUG = False
HOST = '0.0.0.0'
PORT = 5001

As said by David Maze in a comment, the single quotes( ' ) I used in ENTRYPOINT and CMD should be changed to double quotes ( " ), since they are supposed to be JSON arrays.

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