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 **
docker images
` docker ps
docker ps -a
docker start xxxxx
docker exec -it xxxxx/bin/bash
docker stop xxxxx
docker rm xxxxx
docker rmi xxxxx
Recommended Posts