$ docker -v
Docker version 20.10.12, build e91ed57
$ pwd
/home/vagrant/dev/docker/flask
Dockerfile
FROM python:alpine WORKDIR /app COPY ./app /app RUN pip install Flask CMD ["python", "index.py"]
app/index.py
from flask import Flask app = Flask(__name__) @app.route("/") def index(): return "<h1>Hello, Flask</h1>" if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=80)
$ sudo docker image build -t flask .
$ sudo docker run -p 5000:80 -v /home/vagrant/dev/docker/flask/app:/app -d flask
from flask import Flask, render_template app = Flask(__name__) @app.route("/") def index(): values = {"name": "Taro"} return render_template('index.html', data=values) @app.route("/test") def test(): values = {"message": "Hello! This is test page"} return render_template('test.html', data=values) if __name__ == "__main__": app.run(debug=True, host='0.0.0.0', port=80)
$ sudo docker stop 0ef266c41263
### htmlの場合
$ docker build -t some-content-nginx .
$ sudo docker run –name some-nginx -d -p 8080:80 some-content-nginx