DEV Community

Andrés Baamonde Lozano
Andrés Baamonde Lozano

Posted on

4 1

Dockerizing your flask application

First we run our flask app into a apache server, so we need to configure apache server. A full tutorial can be checked here

wsgi file

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0,"/var/www/")

from src.run import app as application
Enter fullscreen mode Exit fullscreen mode

App python


import sys
sys.path.insert(0,"/var/www/")

from app.application import ExampleApi

from config import Configuration

cfg = Configuration(debug=False)
app = ExampleApi(cfg)
if __name__ == "__main__":
    app.run(host=cfg.host,port=cfg.port,debug=cfg.debug)
Enter fullscreen mode Exit fullscreen mode

Dockerfile

FROM ubuntu:12.04

MAINTAINER Andrés Baamonde Lozano

RUN apt-get update && apt-get install -y apache2 libapache2-mod-wsgi python-dev python-pip && apt-get clean && rm -rf /var/lib/apt/lists/*
RUN pip install Flask
#enable mod_wsgi
RUN a2dissite default
RUN a2dissite default-ssl
RUN a2enmod wsgi

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2

COPY src /var/www/src

#Creamos el virtual host
COPY resources/docker/app /etc/apache2/sites-available/appflask
RUN chown -R www-data:www-data /var/www/src
RUN chown www-data:www-data /etc/apache2/sites-available/appflask
RUN a2ensite appflask

EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]
Enter fullscreen mode Exit fullscreen mode

You can check full application at my github

Billboard image

Deploy and scale your apps on AWS and GCP with a world class developer experience

Coherence makes it easy to set up and maintain cloud infrastructure. Harness the extensibility, compliance and cost efficiency of the cloud.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay