Docker Compose Python Flask and MongoDB



pip install docker-compose


examples/flask-mongodb/Dockerfile
FROM python:3.8

COPY requirements.txt /opt/
RUN pip3 install -r /opt/requirements.txt

WORKDIR /opt
#COPY . .

ENV FLASK_APP=app
ENV FLASK_DEBUG=1
CMD  ["flask", "run", "--host", "0.0.0.0", "--port", "5000"]

examples/flask-mongodb/docker-compose.yml
version: '3.8'
services:
  web:
    build: .
    ports:
    - "5001:5000"
    volumes:
    - .:/opt
    links:
    - mongo
  mongo:
    image: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: Secret
    volumes:
      - mongo-data:/data/db
      - mongo-configdb:/data/configdb
volumes:
  mongo-data:
  mongo-configdb:

docker-compose up