[英]How to set service url http://localhost:8080 for running 'docker-compose up web'
I'm relatively new to Docker and I was asked to make my C# WebAPI (.NET 6) start with the url http://localhost:8080 when running the command 'docker-compose up web'.我对 Docker 比较陌生,在运行命令“docker-compose up web”时,我被要求让我的 C# WebAPI (.NET 6) 以 url http://localhost:8080 开头。
I've read many articles but I still haven't found a way to achieve this.我已经阅读了很多文章,但我仍然没有找到实现这一目标的方法。
I'm using Visual Studio 2022.我正在使用 Visual Studio 2022。
Can someone help, please?有人可以帮忙吗?
If your app listens on port 80 like it'll do unless you've changed the configuration, then you map port 80 on the container to port 8080 on the host using a ports:
section like this in your docker-compose.yml file如果您的应用程序在端口 80 上进行侦听,除非您更改了配置,否则您将使用 docker-compose.yml 文件中的
ports:
将容器上的端口 80 映射到主机上的端口 8080:
services:
webapi:
build:
context: ./api
ports:
- 8080:80
Then you'll be able to access it on http://localhost:8080/然后你就可以在 http://localhost:8080/ 上访问它了
Be aware that Swagger isn't available by default when you run a .NET app in a docker container, so you have to access the 'real' API endpoints.请注意,当您在 docker 容器中运行 .NET 应用程序时,默认情况下 Swagger 不可用,因此您必须访问“真正的”API 端点。 If you want Swagger to be available, you need to set the environment variable ASPNETCORE_ENVIRONMENT to 'Development'.
如果您希望 Swagger 可用,则需要将环境变量 ASPNETCORE_ENVIRONMENT 设置为“开发”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.