适用于Windows的Docker IP [英] Docker ip for windows

查看:91
本文介绍了适用于Windows的Docker IP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用一个基本的.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:5000localhost:5000上访问.

您还应确保您接受Program.cs.UseUrls("http://*:5000/")WebHostBuilderProgram.csMain()中的任何主机名.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆