编辑
2023-07-28
运维
00
请注意,本文编写于 544 天前,最后修改于 544 天前,其中某些信息可能已经过时。

目录

gunicorn
Docker打包发布

gunicorn

需要安装gunicorn gevent **注意!**这个模块虽然在win上可以使用pip进行安装,但是在win上是无法使用的,在linux环境下才可以使用!

Docker打包发布

使用Vscode自动生成Dockerfile

Dockerfile
# For more information, please refer to https://aka.ms/vscode-docker-python FROM python:3.8-slim EXPOSE 5002 # Keeps Python from generating .pyc files in the container ENV PYTHONDONTWRITEBYTECODE=1 # Turns off buffering for easier container logging ENV PYTHONUNBUFFERED=1 # 复制模块安装文件到目录中 COPY requirements.txt . #换清华源 RUN python -m pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple #设置工作目录 WORKDIR /app #复制所有文件到工作目录 COPY . /app # Creates a non-root user with an explicit UID and adds permission to access the /app folder # For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app USER appuser # During debugging, this entry point will be overridden. For more information, please refer to https://aka.ms/vscode-docker-python-debug # 使用gunicorn启动项目在5002上 CMD ["gunicorn", "--bind", "0.0.0.0:5002", "wanAlert:app"]

将Dockerfile和项目文件都复制到同一目录下后

bash
[root@localhost flask]# docker build -t flask_app . #查看镜像文件 [root@localhost flask]# docker images #运行下看一下是否有错误 [root@localhost flask]# docker run <imageName> #登入docker hub准备进行上传 [root@localhost flask]# docker login -uname -p #上传至服务器 [root@localhost flask]# docker push <imageName> #到正式服务器上后先登录 后pull下来,然后运行 [root@it-monitoring flask]$ docker run -d -p5000:5002 <imageName>