Super easy! Python + Flask environment in Docker quickly

At Weekend Hackathon I built a Python + Flask environment on Docker with the intention of creating a website

** Download and install ** Download from Get Docker for Mac https://docs.docker.com/docker-for-mac/install/ Extract the downloaded Docker.dmg and complete the installation Tutorial starts after installation Press NEXT STEP to check the operation

** Python + Flask environment **

Dockerfile

FROM python:3.7.4

WORKDIR /app
ADD . /app

RUN apt-get update && apt-get clean;

RUN pip install -r requirements.txt

ENV TZ = "Asia/Tokyo"
ENV FLASK_APP /app/app.py
ENV PYTHONPATH $PYTHONPATH:/app

ENV PORT 8080
EXPOSE 8080

CMD ["python", "app.py"]

Sample app If you want to know the contents of the code, please refer to Document.

weekend-hackathon/  
|-- app  
|   |-- views  
|   |	 `-- sample.py  
|   `-- __init__.py  
|-- app.py  
|-- Dockerfile  
`-- requirements.txt  

weekend-hackathon/requirements.txt

Flask==1.1.2

weekend-hackathon/app/views/sample.py

from flask import Blueprint

sample = Blueprint("sample", __name__)


@sample.route("/")
def index():
    print("sample.index")
    return "sample.index"

weekend-hackathon/app/__init__.py

from flask import Flask
from app.views.sample import sample


def get_app():
    app = Flask(__name__)
    _register_blueprint(app)
    return app


def _register_blueprint(app):
    app.register_blueprint(sample)

weekend-hackathon/app.py

import app

app = app.get_app()

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8080, debug=True)

** Docker build **

$ docker build -t weekend-hackathon .

** Launch Flask **

$ docker run --name weekend-hackathon -p 8080:8080 -v ~/Sites/weekend-hackathon/:/app -it --rm weekend-hackathon

Access http: // localhost: 8080 / sample.index is displayed.

** Reference command **

  1. Image confirmation: docker images `
  2. Container check: docker ps
  3. Container check (stop): docker ps -a
  4. Container start: docker start xxxxx
  5. Container connection: docker exec -it xxxxx/bin/bash
  6. Container stop: docker stop xxxxx
  7. Delete container: docker rm xxxxx
  8. Delete image: docker rmi xxxxx

Recommended Posts

Super easy! Python + Flask environment in Docker quickly
Using venv in Windows + Docker environment [Python]
virtual environment in python
Development environment in Python
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Japanese can be used with Python in Docker environment
Handle environment variables in Python
Super tiny struct in python
HTTP environment variables in Flask
Prepare python3 environment with Docker
Easy password box in Python
Run eclipse in Docker environment (noVNC)
Python is UnicodeEncodeError in CodeBox docker
Install scrapy in python anaconda environment
Until you put Python in Docker
Build Mysql + Python environment with docker
install tensorflow in anaconda + python3.5 environment
Quickly implement REST API in Python
Docker environment update: add Python package
[docker] python3.5 + numpy + matplotlib environment construction
Application development with Docker + Python + Flask
[Docker] Build an environment of python (Flask) + GraphQL (graphene) + MySQL (sqlalchemy)
How to debug Dash (Flask) in Docker + VSCode + remote connection environment
Build and try an OpenCV & Python environment in minutes using Docker
[Python] Super easy test with assert statement
How to access environment variables in Python
Build Jupyter Lab (Python) environment with Docker
Method to build Python environment in Xcode 6
Build a Python + bottle + MySQL environment with Docker on RaspberryPi3! [Easy construction]
[FX] Hit oanda-API in Python using Docker
Page cache in Python + Flask with Flask-Caching
Build a development environment using Jupyter and Flask with Python in Docker (supports both VS Code / code-server)
Create Python + uWSGI + Nginx environment with Docker
I set the environment variable with Docker and displayed it in Python
Created Ubuntu, Python, OpenCV environment on Docker
To reference environment variables in Python in Blender
Quickly try Microsoft's Face API in Python
Environment maintenance made with Docker (I want to post-process GrADS in Python
Launch a Flask app in Python Anywhere
Easy web app with Python + Flask + Heroku
[Python] Quickly create an API with Flask
Easy image processing in Python with Pillow
Launch environment with LineBot + Heroku + Docker + Python
Image sending / receiving memo in Python (Flask)
Introduction to docker Create ubuntu environment in ubuntu
Python garbled in Windows + Git Bash environment
Use WebDAV in a Portable Docker environment
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4
Python local development environment construction template [Flask / Django / Jupyter with Docker + VS Code]
Easy Python data analysis environment construction with Windows10 Pro x VS Code x Docker
Create a Vim + Python test environment in 1 minute
Hello World with gRPC / go in Docker environment
Prepare the execution environment of Python3 with Docker
Ubuntu18.04.05 Creating a python virtual environment in LTS
Python for super beginners Python for super beginners # Easy to get angry
Install python package in personal environment on Ubuntu
What is wheezy in the Docker Python image?
Create a virtual environment with conda in Python
[Python] Build a Django development environment with Docker
Install the python package in an offline environment
Installation of Python3 and Flask [Environment construction summary]