1 Star 1 Fork 0

Tenny / docker-sanic-example

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

ssp_server


使用 docker 部署 python sanic web 应用的基本例子。以及一些 docker 的常用使用命令。

部署流程

1. 构建镜像

docker build -t sanic-e-image .
  1. -t:指定要创建的目标镜像名为 sanic-e-image
  2. .: Dockerfile 文件所在目录

2. 运行容器

docker run -itd -p 8000:8000 --name server sanic-e-image python server.py
  1. -d: 作为后台运行
  2. -i: 以交互模式运行容器,通常与 -t 同时使用
  3. -t: 为容器重新分配一个伪输入终端,通常与 -i 同时使用
  4. -p: 指定端口映射,格式为:主机(宿主)端口:容器端口

3. 配置 nginx

先更改 nginx 全局代理配置,如果 nginx 为通过宝塔安装的,文件地址为:/www/server/nginx/conf/proxy.conf,如果为单独安装的,地址为:nginx/conf.d/forwarded.conf, 内容请参考:Sanic; 然后运行配置修改。

其余的 docker 指令介绍

更多基础的 docker 使用介绍,可以参考 Docker 基础教程

1. docker images: 列出本地主机上的镜像

2. docker rmi sanic-e-image -f: 删除镜像, sanic-e-image 为镜像名称

3. docker ps -a: 列表容器列表

3. docker rm -f server: 删除容器, server 为容器名称

4. docker container prune: 删除所有停止运行的容器

5. docker image prune -a: 删除所有未被容器使用的镜像

6. docker stop server: 停止容器

7. docker restart server: 重启容器

8. docker cp ./app server:/project/: 复制 app 目录到 容器 serverproject 目录下

  1. -f: 强制删除
  2. -a: 列出所有
  3. server: 为容器名称,可以取任意值

完整的应用运行流程

1. 第一次部署

流程就是上述的部署流程的步骤

2. 后续更改源文件后的部署

2.1 requirements.txt 有变化

  1. 重新编译:docker build -t stock_chart .
  2. 更新源文件:docker cp ./app server:/project/
  3. 重启容器: docker restart server

2.2 requirements.txt 无变化,只是更新源文件

  1. 更新源文件:docker cp ./app server:/project/
  2. 重启容器:docker restart server
MIT License Copyright (c) 2023 Tenny Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

使用 docker 部署 python sanic web 应用的基本例子 展开 收起
Python 等 2 种语言
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/towardly/docker-sanic-example.git
git@gitee.com:towardly/docker-sanic-example.git
towardly
docker-sanic-example
docker-sanic-example
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891