# 1、编写Dockerfile文件
[root@ccse ~/python]# vim Dockerfile
FROM centos:7
RUN curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
RUN curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
RUN yum makecache fast;
RUN yum install python3-devel python3-pip -y
COPY app.py /opt
WORKDIR /opt
EXPOSE 8080
CMD ["python3","app.py"]
2、准备文件
[root@ccse ~/python]# vim app.py
coding:utf8
from flask import Flask
app=Flask(__name__)
@app.route('/')
def hello():
return 'hello docker, i am mm'
if __name__=='__main__':
app.run(host='0.0.0.0',port=8080)
3、查看
[root@ccse ~/python]# ll
total 8
-rw-r--r-- 1 root root 344 Dec 3 14:57 Dockerfile
-rw-r--r-- 1 root root 184 Dec 3 14:51 app.py
4、构建镜像
[root@ccse ~/python]# docker build -t mm_python .
Successfully built 04bb727cf38e
Successfully tagged mm_python:latest
5、启动容器
[root@ccse ~/python]# docker run -d --name my_python -p 8080:8080 mm_python
63353ec19497d524efe7f206ae306bdd94cdd39fbc9d75a69aa7dcdf0c414b3e
6、访问宿主机,查看容器内flask web网站
hello docker,i am mm