Skip to content

dbetteb/DockerFlaskApp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DockerFlaskApp

Objective

This repository shows how to launch an API with Docker and Flask in Python.:

Summary

This repository contains all the necessary code to launch a Flask app in a Docker.

Dockerfile

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 in requirements.txt

For more documentation on these commands and on all available Dockerfile commands see online documentation

docker-compose.yml

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

Running the container

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

Alt text

About

Docker Flask App

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published