[Docker] flaskのアプリを作る

$ sudo docker container run –name base -it -p 8080:80 python:3.7.5-slim bash
# pip install flask==1.1.1

server.py

import flask
app = flask.Flask('app server')

@app.route('/')
def index():
	return 'Hello docker'

app.run(debug=True, host='0.0.0.0', port=80)

$ sudo docker container cp server.py base:/
# python server.py
Traceback (most recent call last):
File “server.py”, line 1, in
import os, flask
File “/usr/local/lib/python3.7/site-packages/flask/__init__.py”, line 14, in
from jinja2 import escape
ImportError: cannot import name ‘escape’ from ‘jinja2’ (/usr/local/lib/python3.7/site-packages/jinja2/__init__.py)

### コンテナからファイルを転送
$ sudo docker container cp base:/etc/hosts ./
$ cat hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 300da009fa4e

### コンテナのイメージ化
$ sudo docker commit base c2img1_app
$ sudo docker images;
REPOSITORY TAG IMAGE ID CREATED SIZE
c2img1_app latest 37a4ea8b1a13 5 seconds ago 189MB
$ sudo docker run –rm -p 8080:80 c2img1_app python -u /server.py
$ sudo docker image history c2img1_app

### imageをpush
$ sudo docker image tag c2img1_app ddddocker/c2img1_app:v1.0
$ sudo docker login
$ sudo docker push ddddocker/c2img1_app:v1.0

なんかやべえな…