当前位置 博文首页 > zy7y:Docker部署SayHello(FastAPI)
昨天发了一个SayHello FastAPI版本,今天部署上自己的服务器了
体验地址: http://49.232.203.244:9001/message.html
前置条件:以下在centos7.5 云服务器实验通过
yum -y install git # 安装git curl -sSL https://get.daocloud.io/docker | sh # 安装docker
git clone https://gitee.com/zy7y/sayhello
git clone https://github.com/zy7y/sayhello
上面两个命令选一个执行就可了
部署后端
1. 进入到sayhello目录
cd sayhello
2. 编写API的Dockerfile(如果有请之直接构建镜像- 在下一步)
在sayhello目录下新建如下Dockerfile
FROM python:3.7 COPY . /app WORKDIR ./app RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ EXPOSE 80 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"]
简单说下上面内容做了什么事情,不一定正确加了些个人理解
FROM python:3.7 # 拉取基础镜像python3.7,本机已有该镜像就会使用该镜像,没有就去远端仓库拉取,速度慢就需要换下源地址,百度即可(这里应该就是拉下镜像后弄成了个容器) COPY . /app # 将当前所在目录下所有文件 复制到 容器里面 /app 目录下 WORKDIR ./app # 指定工作目录,我的理解是后面执行的命令 都相当于在这个目录下执行了,根目录的形式吧 RUN pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ # 这步是在容器里面执行 pip 安装依赖 EXPOSE 80 # 将容器中80 端口开放 CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "80"] # 容器运行时将执行 uvicorn main:app --host 0.0.0.0 --port 80 启动服务
3. 构建镜像
docker build -t sayhello .
4. 运行容器
会自动执行dockerfile里面的CMD命令
docker run -d --name sayhello-fastapi -p 8000:80 sayhello
5. 访问
IP:8000/message
,得到如下页面部署前端
先确认message.html中的
baseURL
是不是后端服务的IP地址(127.0.0.1 不行)1. 进入到sayhello/static目录
cd sayhello/static/
2. 编写Dockerfile文件(如果有请直接进入第三步)
FROM nginx:1.15.2-alpine COPY . /usr/share/nginx/html COPY nginx.conf /etc/nginx/conf.d/default.conf EXPOSE 80 CMD ["nginx", "-g", "daemon off;"]
3. 构建镜像
docker build -t sayhello-front .
4. 启动容器
docker run -d --name sayhello-front-9000 -p 9001:80 sayhello-front
5. 访问IP:9001/message.html
参考资料及感谢
感谢资料提供者/作者
- https://aqzt.com/bubble/6513.html
- https://www.cnblogs.com/tian874540961/p/11916832.html
- https://www.runoob.com/docker/docker-dockerfile.html
下一篇:没有了
最新 更多<<
zy7y:Docker部署SayHello(FastAPI) 说人话:通俗易懂的解释:什么是API 华为云开发者社区:LiteOS调测利器:backtrace函数原理知多少 大数据学习与分享:Spark SQL如何选择join策略 程序员欣宸:jackson学习之四:WRAP_ROOT_VALUE(root对象) sherlock_lin:libuv工作队列 throwable:冷饭新炒:理解JDK中UUID的底层实现 卤蛋实验室:🙈 如何隐藏你的热更新 bundle 文件? sheng.chao:.net core 和 WPF 开发升讯威在线客服与营销系统: zy7y:FastAPI项目实战:SayHello(FastAPI + vue.js + axios + e sewain:C指针的这些使用技巧,掌握后立刻提升一个Level Grant_Allen:Azure Terraform(七)利用Azure DevOps 实现自动 _Fatman:一篇文章带你初步了解—CSS特指度 编程我的一切:Shell从入门到精通 路边两盏灯:【Azure Developer】在Azure Resource Graph Explor WindrunnerMax:Vue中组件间通信的方式 SpringLeee:盘点大厂的那些开源项目 - 华为 天乔巴夏丶:Java并发包源码学习系列:阻塞队列实现之PriorityBl 又拍云:个推异常值检测和实战应用 雪山飞猪:MySQL如何加锁控制并发 itbsl:DNS是如何工作的? iR-Poke:day132:2RenMJ:MJ需求文档&MJ游戏流程&Egret白 空壳先生:kubernetes用户权限管理工具permission-manager jiulang:开源AwaitableCompletionSource,用于取代TaskCompleti 又拍云:网页出现不河蟹弹窗?那是被劫持了! 0nTheRoad:基于源码分析Vue的nextTick .NET快速开发框架:.NET Core部署到linux(CentOS)最全解决方案, 段小辉:网络流量预测入门(二)之LSTM介绍 BWH_Steven:如何讲清楚 Java 面向对象的问题与知识?(类与对象 晓飞的算法工程笔记:ESPNet/ESPNetV2:空洞卷积金字塔 | 轻量级