【发布时间】:2021-11-29 02:59:15
【问题描述】:
我正在创建一个 dotnet 6 webapi 应用程序来提供 REST API。我可以在 Mac 上创建项目并通过终端运行并访问 http://localhost:5000/swagger/ 以查看 Swagger。当我尝试通过运行 docker-compose run --rm server 的 Docker 运行时,问题就出现了。我无法访问 Swagger 并在浏览器选项卡上收到 HTTP ERROR 403。我也在 API/Program.cs 的 app.UseHttpsRedirection(); 中评论了这一行。
我的文件夹结构是
my-project
-API/
- Folder with the webapi template
-dockerfiles/
- Dockerfile.dev
app.sln
docker-compose.yml
docker-compose.yml
version: '3.8'
services:
server:
build:
context: ./dockerfiles
dockerfile: Dockerfile.dev
volumes:
- ./:/app
ports:
- '5000:5000'
- '5001:5001'
Dockerfile.dev
FROM mcr.microsoft.com/dotnet/sdk:6.0
WORKDIR /app/API/
RUN dotnet dev-certs https
EXPOSE 5000
CMD ["dotnet", "watch", "run"]
运行时在控制台输出docker-compose run --rm server
watch : Started
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app/API/
API/Properties/launchSettins.json
"profiles": {
"API": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
【问题讨论】:
标签: .net docker docker-compose