基于Python+Git+SSH+Flask的镜像 Dockerfile文件分享
Posted xbw12138
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了基于Python+Git+SSH+Flask的镜像 Dockerfile文件分享相关的知识,希望对你有一定的参考价值。
说明
积累了一个比较稳定实用的Flask框架 Dockerfile镜像
Dockerfile文件
FROM python:3.7.3
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak && \\
echo "deb http://mirrors.aliyun.com/debian/ stretch main non-free contrib" >/etc/apt/sources.list && \\
echo "deb-src http://mirrors.aliyun.com/debian/ stretch main non-free contrib" >>/etc/apt/sources.list && \\
echo "deb http://mirrors.aliyun.com/debian-security stretch/updates main" >>/etc/apt/sources.list && \\
echo "deb-src http://mirrors.aliyun.com/debian-security stretch/updates main" >>/etc/apt/sources.list && \\
echo "deb http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib" >>/etc/apt/sources.list && \\
echo "deb-src http://mirrors.aliyun.com/debian/ stretch-updates main non-free contrib" >>/etc/apt/sources.list && \\
echo "deb http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib" >>/etc/apt/sources.list && \\
echo "deb-src http://mirrors.aliyun.com/debian/ stretch-backports main non-free contrib" >>/etc/apt/sources.list
RUN apt-get update && \\
apt-get install -y vim && \\
apt-get install -y openssh-server && \\
rm -rf /var/lib/apt/lists/* && \\
apt-get clean
RUN echo 'root:bjut2019' |chpasswd
RUN sed -ri 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config && \\
sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN mkdir -p /var/run/sshd
EXPOSE 22
EXPOSE 5000
CMD ["/usr/sbin/sshd", "-D"]
COPY . /app
WORKDIR /app
RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
ENTRYPOINT ["gunicorn"]
CMD ["-w", "4", "-b", "0.0.0.0:5000", "--log-level=info", "app:app"]
requirements.txt
alembic==0.8.10
aniso8601==8.0.0
attrs==19.1.0
Babel==2.7.0
blinker==1.4
certifi==2019.9.11
chardet==3.0.4
Click==7.0
Flask==1.1.1
Flask-BabelEx==0.9.3
Flask-Cache==0.13.1
Flask-Cors==3.0.8
Flask-Docs==0.1.2
Flask-HTTPAuth==3.3.0
Flask-Login==0.4.1
Flask-Mail==0.9.1
Flask-Migrate==2.4.0
Flask-Principal==0.4.0
Flask-RESTful==0.3.7
Flask-Script==2.0.6
Flask-Security==3.0.0
flask-sqlacodegen==1.1.6.1
Flask-SQLAlchemy==2.4.0
Flask-WTF==0.14.2
gunicorn==20.0.4
idna==2.8
importlib-metadata==1.1.0
inflect==3.0.2
itsdangerous==1.1.0
jenkspy==0.1.5
Jinja2==2.10.1
jsonschema==3.0.2
Mako==1.1.0
MarkupSafe==1.1.1
more-itertools==8.0.0
networkx==2.5
numpy==1.17.4
passlib==1.7.1
Pymysql==0.9.3
pyproj==2.4.2.post1
pyrsistent==0.15.4
python-dateutil==2.8.1
python-editor==1.0.4
pytz==2019.2
redis==3.4.1
requests==2.22.0
six==1.12.0
speaklater==1.3
SQLAlchemy==1.3.8
urllib3==1.25.6
Werkzeug==0.16.0
WTForms==2.2.1
zipp==0.6.0
使用
docker build -t name:latest .
docker run -it -d --restart=always -p 10022:22 -p 5000:5000 -v /local_path:/app name:latest
将Dockerfile文件放置在Flask项目根目录里,这样修改Flask代码后,直接docker restart 容器id就可以更新了,也可以通过Git拉取代码。
以上是关于基于Python+Git+SSH+Flask的镜像 Dockerfile文件分享的主要内容,如果未能解决你的问题,请参考以下文章
Python Web实战 - 基于Flask实现的黄金点游戏