如何设置服务URL http:// localhost:8080用于运行

发布于 2025-02-02 12:24:00 字数 187 浏览 2 评论 0原文

我对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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

这个俗人 2025-02-09 12:24:00

如果您的应用在端口80上像“这样”聆听,除非您更改了配置,否docker-compose.yml文件

services:
  webapi:
    build:
      context: ./api
    ports:
      - 8080:80

,然后您可以在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 file

services:
  webapi:
    build:
      context: ./api
    ports:
      - 8080:80

Then 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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文