skip to Main Content

I need to create a docker-compose file for flask based API back end application. But this application is based on several other libraries following. All need to run on docker containers only. Can you suggest how will be the docker-compose file and related if any?

  • psycopg2
  • aniso8601==8.0.0
  • argon2-cffi==19.2.0
  • certifi==2019.11.28
  • cffi==1.14.0
  • chardet==3.0.4
  • click==7.1.1
  • cryptography==2.9
  • defusedxml==0.6.0
  • Flask==1.1.2
  • Flask-Caching==1.8.0
  • Flask-JWT-Extended==3.24.1
  • Flask-Login==0.4.1
  • Flask-OAuthlib==0.9.5
  • Flask-OpenID==1.2.5
  • Flask-RESTful==0.3.8
  • Flask-SQLAlchemy==2.4.1
  • flask-swagger==0.2.13
  • Flask-WTF==0.14.3
  • graphviz==0.14
  • gunicorn==19.10.0
  • idna==2.9
  • itsdangerous==0.24
  • Jinja2==2.10.1
  • kazoo==2.5.0
  • Mako==1.1.2
  • MarkupSafe==1.1.1
  • oauthlib==2.1.0
  • passlib==1.7.2
  • pika==1.1.0
  • pycparser==2.20
  • PyJWT==1.7.1
  • pykafka==2.8.0
  • pymemcache==3.1.1
  • pymongo==3.5.1
  • pypyodbc==1.3.5.2
  • python-dateutil==2.8.1
  • python-editor==1.0.4
  • python3-openid==3.1.0
  • pytz==2019.3
  • PyYAML==5.3.1
  • redis==3.5.0
  • requests==2.23.0
  • requests-oauthlib==0.8.0
  • six==1.14.0
  • SQLAlchemy==1.3.15
  • SQLAlchemy-Utils==0.36.3
  • tabulate==0.8.7
  • urllib3==1.25.8
  • Werkzeug==0.15.3
  • WTForms==2.2.1
  • python-ldap

2

Answers


  1. My example is with Django but you can use for your flask container too

    You can create a Dockerfile, for example if your flask container run within app folder of the container:

    docker-compose.yml:

    version: '3'
    
    services:
    
    web:
        build: .
        volumes:
          - .:/app
        ports:
          - "${WEB_HOST}:${WEB_HOST}"
        depends_on:
          - mysql # if you have database in another container
        environment:
          - PYTHONUNBUFFERED=1
        command: python manage.py runserver 0.0.0.0:${WEB_HOST} #or what command you use to start your flask server
    

    You need a requirements.txt file to list all your packages

    And write a Dockerfile to install all package into app container folder when run docker-compose up:

    FROM python:3.7.5-buster
    ADD requirements.txt /app/requirements.txt
    ADD . /app/
    WORKDIR /app/
    RUN pip install -r requirements.txt
    
    Login or Signup to reply.
  2. The best way here is to go through this file – https://docs.docker.com/compose/gettingstarted/. But if you want to try it fast, then here is some short instructions:

    1. create a requirements.txt file with all dependencies (list of libs with versions)
    2. create a Dockerfile
    FROM python:3.7-alpine
    
    WORKDIR /code
    
    ENV FLASK_APP app.py
    ENV FLASK_RUN_HOST 0.0.0.0
    
    RUN apk add --no-cache gcc musl-dev linux-headers
    COPY requirements.txt requirements.txt
    
    RUN pip install -r requirements.txt
    COPY . .
    
    CMD ["flask", "run"]
    
    1. create docker-compose.yml file:
    version: '3'
    services:
      web:
        build: .
        ports:
          - "5000:5000"
    

    Of course in reality it will be more complex (you will have Data Base, maybe Redis, etc – for big project this tool can help you https://github.com/cookiecutter-flask/cookiecutter-flask)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search