>如何从一个python程序打包成为image,然后上传到dockerhub,最后下载image,生成对应的container容器。走咱们一起走个流程下来。
python程序
- 编写python程序
mkdir flask-hello-world cd flask-hello-world/ vim app.py
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hell():
return "hello docker public attention:idig88"
if __name__=='__main__':
app.run(port=8888)
- 运行python程序
python app.py
#安装flask插件
sudo yum -y install epel-release
sudo yum -y install python-pip
pip install flask
python app.py
编写Dockerfile文件
vim Dockerfile
FROM python:2.7
LABEL maintainer="zhugeaming"
RUN mv /etc/apt/sources.list /etc/apt/sources.list.bak
RUN echo "deb http://mirrors.163.com/debian/ jessie main non-free contrib" >/etc/apt/sources.list
RUN echo "deb http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
RUN echo "deb-src http://mirrors.163.com/debian/ jessie main non-free contrib" >>/etc/apt/sources.list
RUN echo "deb-src http://mirrors.163.com/debian/ jessie-proposed-updates main non-free contrib" >>/etc/apt/sources.list
RUN apt-get update
RUN pip install flask
COPY app.py /app/
WORKDIR /app
EXPOSE 8888
CMD ["python","app.py"]
docker image ls
运行container
docker run zhugeaming/flask-hello-world
#后台运行
docker run -d zhugeaming/flask-hello-world
>容器有2个一个是刚才执行,一个后台执行的,后台直接执行。不加入-d的已经退出了。
PS:本次就是做了个实战,通过四步
- 代码编写好
- 环境python环境
- 第三方依赖
- 执行命令
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦