我正试图在docker容器中运行Rhino Compute,并面临一个奇怪的问题。我已经使用下面的Dockerfile构建了一个映像,当我在本地运行它时,没有问题。
# escape=`
# see https://discourse.mcneel.com/t/docker-support/89322 for troubleshooting
# NOTE: use 'process' isolation to build image (otherwise rhino fails to install)
### builder image
FROM mcr.microsoft.com/dotnet/sdk:5.0 as builder
# copy everything, restore nuget packages and build app
COPY src/ ./src/
RUN dotnet publish -c Release -r win10-x64 --self-contained true src/compute.sln
### main image
# tag must match windows host for build (and run, if running with process isolation)
# e.g. 1903 for Windows 10 version 1903 host
FROM mcr.microsoft.com/windows:1809
#Copy the fonts and font install script
COPY fonts/* fonts/
COPY InstallFont.ps1 .
#Run font install scriptin powershell
RUN powershell -ExecutionPolicy Bypass -Command .InstallFont.ps1
# install .net 4.8 if you're using the 1809 base image (see https://git.io/JUYio)
# comment this out for 1903 and newer
RUN curl -fSLo dotnet-framework-installer.exe https://download.visualstudio.microsoft.com/download/pr/7afca223-55d2-470a-8edc-6a1739ae3252/abd170b4b0ec15ad0222a809b761a036/ndp48-x86-x64-allos-enu.exe `
&& .dotnet-framework-installer.exe /q `
&& del .dotnet-framework-installer.exe `
&& powershell Remove-Item -Force -Recurse ${Env:TEMP}*
# install rhino (with “-package -quiet” args)
# NOTE: edit this if you use a different version of rhino!
# the url below will always redirect to the latest rhino 7 (email required)
# https://www.rhino3d.com/download/rhino-for-windows/7/latest/direct?email=EMAIL
RUN curl -fSLo rhino_installer.exe https://www.rhino3d.com/download/rhino-for-windows/7/latest/direct?email=<myemail> `
&& .rhino_installer.exe -package -quiet `
&& del .rhino_installer.exe
# (optional) use the package manager to install plug-ins
# RUN ""C:Program FilesRhino 7SystemYak.exe"" install jswan
# copy compute app to image
COPY --from=builder ["/src/dist", "/app"]
WORKDIR /app
# bind rhino.compute to port 5000
EXPOSE 5000
# uncomment to build core-hour billing credentials into image (not recommended)
# see https://developer.rhino3d.com/guides/compute/core-hour-billing/
#ENV RHINO_TOKEN=
CMD ["rhino.compute/rhino.compute.exe"]
应用程序代码在这里:https://github.com/mcneel/compute.rhino3d
如前所述,当我对localhost:5000
旋转时,容器内部的一切都正常工作,没有任何问题。但是,当我尝试从主机curl(在运行docker run -p nodeport:containerport imagename
之后)时,我无法得到任何响应。我不确定它是否与防火墙或Dockerfile中的任何东西没有正确配置有关。
任何帮助都是感激的。
默认情况下,EXPOSE指令不公开可从主机访问的容器端口。换句话说,它只使指定的端口可用于容器间交互。例如,假设你有一个Node.js应用程序和一个Redis服务器部署在同一个Docker网络上。为了确保Node.js应用程序与Redis服务器通信,Redis容器应该公开一个端口。如果您检查官方Redis映像的Dockerfile,其中包含一行显示EXPOSE 6379。这就是允许两个容器相互通信的原因。因此,当你的Node.js应用程序连接到Redis容器的6379端口时,EXPOSE指令是确保容器间通信发生的。
你不能通过Dockerfile发布一个端口到你的主机。您应该通过docker-compose完成该操作。Yml文件或通过命令行。在用Dockerfile构建映像之后,您可以使用下面的命令将容器的5000端口发布到主机的5000端口。
docker run -it image:tag -p 5000:5000
我怀疑问题可能与' localhost '有关,因为它只从内部响应localhost,而不会从其他任何地方响应。我们在Dockerfile中添加了。net变量ASPNETCORE_URLS
。
# bind rhino.compute to port 5000
ENV ASPNETCORE_URLS="http://*:5000"
EXPOSE 5000
这将确保应用程序正在监听接口,而不仅仅是本地主机,并解决了问题