我知道有很多关于这个的讨论,但没有一个提议的解决方案对我有用,所以我至少必须知道我是否做错了什么或者我是否遇到了限制。
步骤 1. 我从 Visual Studio 创建了默认的 .NET Core 2.0 WEB API 项目,这里没什么特别的,输出类型设置为控制台应用程序,从 Visual Stuido 2017 社区运行正常。
第 2 步。我安装了最新的 Docker Toolbox,因为我运行的是 Windows 10 家庭版,它还安装了 Virtual Box。
步骤 3. 我在 sln 旁边添加了以下 docker 文件:
FROM microsoft/aspnetcore-build:2.0
WORKDIR /app
EXPOSE 80
COPY . .
RUN dotnet restore
RUN dotnet build
WORKDIR /app/DockerSample
ENTRYPOINT dotnet run
第 4 步。我使用“docker build -t sample1”之类的命令成功构建了映像。
Step 5. 容器成功开始运行,它是通过以下命令'docker run -d -p 8080:80 sample1'启动的
步骤 6. 使用命令提取有关容器docker logs c6
的信息 显示以下信息:
这里有趣的是服务正在侦听的地址,这似乎与我直接从 Visual Studio 运行服务时得到的地址相同。
这是在 Virtual box 中运行的虚拟机的服务地址吗?为什么端口不是我在“运行”命令中提到的 8080 或 80 ?
容器看起来不错,类似于:
第 7 步。
现在开始尝试从 Windows 10 机器访问服务的乐趣,使用像http://localhost:8080/values/api这样的调用是不可能的我也尝试了像http://192.168.99.100:8080/values/api这样的调用,其中 192.168 .99.100 是默认 docker 机器的地址。
我还尝试了类似“ http://172.17.0.2:8080/values/api ”的方法,其中 IP 地址是在像“docker inspect a2”这样的调用后获得的,将端口更改为 80 没有帮助:)。尝试将端口号更改为 80 或 58954 ,红色显示为正在侦听的端口号没有帮助。Windows 防火墙或任何其他防火墙也已停止。
我试图从 VirtualBox 转发,有类似的东西
尝试更改主机和来宾之间的 80 和 8080 端口也不起作用。
Basically none of the suggested solutions I found did not gave me the chance to hit the service from my Windows machine.
Mainly I was following this tutorial https://www.stevejgordon.co.uk/docker-for-dotnet-developers-part-2 which explains quite well what should be done only that at some point is using the Docker Desktop for Windows so the Docker Toolbox was left behind.
Do you know what should I do so that I can hit the service from the docker container ?
In docker compose (visual studio add docker integration "docker-compose.yml") set this:
version: '3.4'
services:
webapi.someapi:
image: ${DOCKER_REGISTRY-}somenamesomeapi
build:
context: .
dockerfile: ../webapi/Dockerfile
environment:
- ASPNETCORE_URLS=https://+:443;http://+:80
- ASPNETCORE_HTTPS_PORT=443
ports:
- "80:80"
- "443:443"
in lunch settings specify your app to start on ports 80 and 443 https
Docker for visual studio code: https://marketplace.visualstudio.com/items?itemName=PeterJausovec.vscode-docker
按照以下步骤编排您的容器:https : //marketplace.visualstudio.com/items?itemName=PeterJausovec.vscode-docker
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句