## Docker中配置Flask
#### 相关python库 requirement.txt
```
Flask==1.1.1
flask-sqlacodegen==1.1.6.1
Flask-SQLAlchemy==2.4.1
Flask-WTF==0.14.3
numpy==1.17.4
pandas==0.25.3
PyJWT==1.7.1
PyMySQL==0.9.3
python-dateutil==2.8.1
python-dotenv==0.10.3
uWSGI==2.0.18
```
#### Dockerfile
``` Dockerfile
FROM python:3.7
COPY requirement.txt /home/
RUN /bin/cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone && \
pip install -r /home/requirement.txt -i https://pypi.douban.com/simple/
EXPOSE 5000
CMD ["uwsgi","/home/ad/uwsgi.ini"]
```
#### uwsgi.ini
``` ini
[uwsgi]
chdir=/home/ad/
wsgi-file=/home/ad/app.py
callable=app
http=0.0.0.0:5000
; socket=:5001
# socket=/home/log/ad/uwsgi.sock
processes=4
threads=2
master=true
chmod-socket=666
vacuum=true
die-on-term=true
logfile-chmod=777
# home=/home/venv
py-autoreload=1
reload-mercy=1
worker-reload-mercy=1
```
## 操作
``` Bash
# 创建镜像
docker build -t myFlask:1.0 ./
# 运行
docker run -it --name myflask -p 5000:5000 -v /home/logs/myflask:/home/logs/myflask:rw -v /home/myflask:/home/myflask myFlask:1.0
# 进入容器查看
docker exec -it myflask /bin/bash
# 清空所有容器
docker rm $(docker ps -aq)
```
## docker-compose.yml
``` yml
version: "3.3"
services:
myflask:
image: myFlask:1.0
container_name: myflask
restart: always
volumes:
- "/home/myflask:/home/myflask"
- "/home/logs/myflask:/home/logs/myflask:rw"
ports:
- "5000:5000"
networks:
- mfnet
networks:
mfnet:
```