简体   繁体   English

如何设置服务 url http://localhost:8080 以运行“docker-compose up web”

[英]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.

相关问题 http:// localhost:8080 /上没有端点 - There was no endpoint at http://localhost:8080/ Docker:应用程序通过docker-compose工作正常,但是如何通过Visual Studio和调试运行它? - Docker: applications works fine via docker-compose up, but how to run it via Visual Studio and debug? 如何将 IdentityServer 与 docker-compose 一起使用? - How to use IdentityServer with docker-compose? 如何从Azure中托管的WCF服务访问TFS URL'http:// msitvstf1:8080 / tfs / RXD' - How to access TFS URL 'http://msitvstf1:8080/tfs/RXD' from WCF Service hosted in Azure 当 web 应用程序作为服务在 .net core (2.2) 中运行时如何设置远程 url - How to set remote url when web app is running as a service in .net core (2.2) Docker 设置中的 .Net Core 3.1 MSSQL 后端:Docker-compose up 产生连接失败 - .Net Core 3.1 MSSQL backend in Docker setup: Docker-compose up producing connection failure .net核心应用程序无法连接到RabbitMQ(两者都通过docker-compose在docker网络中运行) - .net core app ca't connect to rabbitMQ (both running in a docker network via docker-compose) 为什么我的 .NET Web API 应用程序在使用 docker-compose 时无法连接到 docker 上的 MySQL? - Why does my .NET web API application not connect to MySQL on docker when using docker-compose? 在http:// localhost:8080 / kestrel / SystemService中没有监听端点 - There was no endpoint listening at http://localhost:8080/kestrel/SystemService 使用docker-compose运行docker image - Run docker image with docker-compose
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM