如何设置服务URL http:// localhost:8080用于运行
我对Docker的新手相对较新,被要求使我的C#WebAPI(.NET 6)从URL http:// localhost:8080开始运行命令“ Docker-Compose web”时。
我已经阅读了许多文章,但我仍然没有找到实现这一目标的方法。
我正在使用Visual Studio2022。
有人可以提供帮助吗?
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'.
I've read many articles but I still haven't found a way to achieve this.
I'm using Visual Studio 2022.
Can someone help, please?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的应用在端口80上像“这样”聆听,除非您更改了配置,否docker-compose.yml文件
,然后您可以在http:// localhost:8080/
请注意,当您在Docker容器中运行.NET应用程序时,默认情况下无法使用Swagger,因此您必须必须访问“真实” API端点。如果您希望Swagger可用,则需要将环境变量aspnetcore_environment设置为“开发”。
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 fileThen you'll be able to access it on 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. If you want Swagger to be available, you need to set the environment variable ASPNETCORE_ENVIRONMENT to 'Development'.