访问Docker上的API文档
我有一个FastApi,当我与Uvicorn一起运行时,我可以通过Localhost/Docs打开其API文档。
当我在Docker上有这个Fastapi时,我将看不到API文档。 我需要为API文档添加一个额外的Docker容器吗?
这是我的Docker组成文件:
version: "3.7"
services:
web:
build: ui
ports:
- 80:80
depends_on:
- api
api:
build: app
environment:
- PORT=80
ports:
- 8020:80
我用docker-compose-Build
运行它。
我尝试了localhost/docs和localhost/swagger/index.html,但我看不到Docker上的API文档。
这是我的fastapi docker文件:
FROM python:3.9
COPY requirements.txt /app/
RUN pip install -r /app/requirements.txt
COPY ./ /app
WORKDIR /app
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8020"]
I have a fastapi and when I run it with uvicorn, I am able to open its api documentation through localhost/docs.
When I have this fastapi on docker, I am not able to see the API documentation.
Do I need to add an extra docker container for the API documentation?
Here is my docker compose file:
version: "3.7"
services:
web:
build: ui
ports:
- 80:80
depends_on:
- api
api:
build: app
environment:
- PORT=80
ports:
- 8020:80
and I run it with docker-compose up --build
.
I tried localhost/docs and localhost/swagger/index.html and I wasn't able to see the API documentation on docker.
Here is my fastapi docker file:
FROM python:3.9
COPY requirements.txt /app/
RUN pip install -r /app/requirements.txt
COPY ./ /app
WORKDIR /app
CMD ["uvicorn", "api:app", "--host", "0.0.0.0", "--port", "8020"]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为问题是不匹配端口。
尝试
然后您可以在
http://0.0.0.0.0.0.8020/docs
I think the problem is mismatching ports.
try
then you can see docs at
http://0.0.0.0:8020/docs