适用于Windows的Docker IP [英] Docker ip for windows
问题描述
我正在用一个基本的.NET核心项目测试Docker.我从此docker文件构建图像:
FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app/API
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
我运行它,它运行得很顺利.现在唯一的问题是,它在什么IP上运行?
我正在Windows上运行Docker!
致谢
您已经在内部公开了端口,所以我唯一建议的另一件事就是在启动映像时检查您是否也在打开端口:>
docker run -it -p 5000:5000 <imagename>
这会将实例内部的端口5000打开到本地计算机上的端口5000,然后应该可以在127.0.0.1:5000
或localhost:5000
上访问.
您还应确保您接受Program.cs
中.UseUrls("http://*:5000/")
中WebHostBuilder
中Program.cs
中Main()
中的任何主机名.
I'm testing out Docker with a basic .NET core project. I Build and image from this docker file:
FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app/API
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
CMD ["dotnet", "run", "--server.urls", "http://*:5000"]
I run it and it goes flawlessly. Now the only problem is, on what IP is it running ?
I'm running Docker on Windows!
Regards
You're already exposing the port internally, so the only other thing I can suggest is to check you are opening the port when launching your image too:
docker run -it -p 5000:5000 <imagename>
This will open port 5000 inside the instance to port 5000 on your local machine, and should then be accessible on 127.0.0.1:5000
or localhost:5000
.
You should also ensure that you are accepting any host name within Main()
in Program.cs
with .UseUrls("http://*:5000/")
on your WebHostBuilder
.
这篇关于适用于Windows的Docker IP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!