flask环境
Dockerfile文件
FROM python:3.6.4
# 复制文件
COPY app /code/app
COPY requirements.txt /code
COPY run.sh /code
# 安装依赖
# RUN apt-get update
RUN pip install -r /code/requirements.txt
WORKDIR /code
# 执行命令
CMD ["/bin/bash","/code/run.sh"]
requirements.txt
requests==2.22.0
Flask==1.0.2
run.sh
#!bin/bash
echo "run start";
uname -a;
python /code/app/start.py;
# 前台一直执行
# python;
start.py
#! /usr/bin/env python
# -*- coding: utf-8 -*-
import os
from flask import Flask, make_response, send_from_directory, jsonify, request
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello world!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=3001)
文件结构图
image.png
容器的环境
image.png
上传到阿里云的仓库镜像
docker push registry.cn-hangzhou.aliyuncs.com/xin_python/flask
docker run -it -d -p 3001:3001 --name p2 --privileged=true registry.cn-hangzhou.aliyuncs.com/xin_python/flask
网友评论