This repository shows how to launch an API with Docker and Flask in Python.:
This repository contains all the necessary code to launch a Flask app in a Docker.
FROM python:3.6-slim
MAINTAINER Dimitri Bettebghor
RUN apt-get update && apt-get install -qq -y \
build-essential libpq-dev --no-install-recommends
ENV INSTALL_PATH /webapp
RUN mkdir -p $INSTALL_PATH
WORKDIR $INSTALL_PATH
COPY requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD gunicorn -b 0.0.0.0:3333 --access-logfile - "webapp.app:app"
Description :
-
FROM
indicates which Docker image is to be used -
MAINTAINER
gives the name of the author of the Docker image -
RUN
launches packages installation -
ENV
sets environment variable -
RUN
mkdir creates a repository -
WORKDIR
sets the working directory -
COPY
copies the requirements file where Python modules are listed -
RUN pip
installs the Python modules listed inrequirements.txt
For more documentation on these commands and on all available Dockerfile
commands see online documentation
version: '3'
services:
webapp:
build: .
command: >
gunicorn -b 0.0.0.0:3333
--access-logfile -
--reload
"webapp.app:app"
environment:
PYTHONUNBUFFERED: 'true'
volumes:
- '.:/webapp'
ports:
- '3333:3333'
docker-compose.yml
file. Documentation on docker-compose
file can be found here
Now in a terminal, run
docker-compose up --build
You should see all the steps, and if everything works you can now open a browser and type in the URL
localhost:3333/users/Toto
and you should see