VS React-Redux容器连接到api-sqlserver容器

问题描述:

遇到了将VS React-Redux模板部署为连接到api docker容器的docker容器的问题.以下是给定的事实:

Got a problem with VS React-Redux template deployed as a docker container connecting to api docker container. Below are the given facts:

事实1.我在docker hub中有3个Docker Windows容器( https://hub.docker.com/repository/docker/solomiosisante/test ):

Fact 1. I've got 3 Docker Windows containers in docker hub (https://hub.docker.com/repository/docker/solomiosisante/test):

  1. solomiosisante/test:sqlserver
  2. solomiosisante/test:api
  3. solomiosisante/test:react

事实2.我设法通过创建docker nat网络使api连接到sqlserver并使它们通信.API容器可以从sqlserver容器获取并显示数据.

Fact 2. I managed to make the api connect to sqlserver and make them communicate by creating a docker nat network. API container can get and display data from the sqlserver container.

事实3.我还使用相同的nat网络运行react容器.

Fact 3. I also run the react container using the same nat network.

事实4.我可以成功地docker运行react容器.

Fact 4. I can successfully docker run the react container.

事实5.它们都在运行Net 5.0(VS项目),但是对于sqlserver不确定,因为我只是从microsoft/mssql-server-windows-developer映像中获得的.

Fact 5. They are all running Net 5.0 (VS projects), but not sure with sqlserver because I just got it from microsoft/mssql-server-windows-developer image.

事实6.我可以从Visual Studio运行react项目,并在浏览器中毫无问题地加载页面.(并且它连接到api容器)

Fact 6. I can run the react project from visual studio and load the pages in the browser with no problem. (and it connects to api container)

问题::我无法使react容器浏览到我的任何页面.浏览器说无法连接超时.

Problem: I could not make the react container browse to any of my pages. Browser says it can't be reached connection timed out.

反应项目Dockerfile:

# escape=`
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

#Depending on the operating system of the host machines(s) that will build or run the containers, the image specified in the FROM statement may need to be changed.
#For more information, please see https://aka.ms/containercompat

###########################################################################################
FROM mcr.microsoft.com/powershell:nanoserver-1903 AS downloadnodejs
RUN mkdir -p C:\nodejsfolder
WORKDIR C:\nodejsfolder
SHELL ["pwsh", "-Command", "$ErrorActionPreference = 'Stop';$ProgressPreference='silentlyContinue';"]
RUN Invoke-WebRequest -OutFile nodejs.zip -UseBasicParsing "https://nodejs.org/dist/v15.6.0/node-v15.6.0-win-x64.zip"; `
Expand-Archive nodejs.zip -DestinationPath C:\; `
Rename-Item "C:\node-v15.6.0-win-x64" c:\nodejs

###########################################################################################
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

###########################################################################################
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
RUN mkdir -p C:\nodejs
COPY --from=downloadnodejs C:\nodejs\ C:\nodejs

# needs to use ContainerAdministrator to be able to setx path
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\nodejs"
USER ContainerUser
RUN echo %PATH%
#RUN echo "%PATH%"
#RUN echo $PATH
#RUN echo {$PATH}

WORKDIR /src
#COPY ["Consequence.React/Consequence.React.csproj", "Consequence.React/"]
#COPY ["Consequence.API/Consequence.API.csproj", "Consequence/"]
#COPY ["Consequence.EF/Consequence.EF.csproj", "Consequence.EF/"]
#COPY ["Consequence.Repositories/Consequence.Repositories.csproj", "Consequence.Repositories/"]

COPY . .
RUN dotnet restore "Consequence.React/Consequence.React.csproj"

#WORKDIR "/src/Consequence.React/ClientApp"
#RUN npm install
#RUN npm audit fix
WORKDIR "/src/Consequence.React"
RUN dotnet build "Consequence.React.csproj" -c Release -o /app/build

WORKDIR /src
RUN dir /s

WORKDIR "/src/Consequence.React"

###########################################################################################
FROM build AS publish
RUN dotnet publish "Consequence.React.csproj" -c Release -o /app/publish

###########################################################################################
FROM base AS final
RUN mkdir -p C:\nodejs
COPY --from=downloadnodejs C:\nodejs\ C:\nodejs

# needs to use ContainerAdministrator to be able to setx path
USER ContainerAdministrator
RUN setx /M PATH "%PATH%;C:\nodejs"
USER ContainerUser

RUN echo %PATH%

WORKDIR /app
COPY --from=publish /app/publish .
RUN dir /s

ENV ASPNETCORE_URLS="https://+;http://+" 
ENV ASPNETCORE_HTTP_PORT=8089
ENV ASPNETCORE_HTTPS_PORT=44319 
ENV ASPNETCORE_Kestrel__Certificates__Default__Password="P@ssw0rd123" 
ENV ASPNETCORE_Kestrel__Certificates__Default__Path=/src/certs/consequence.pfx

ENTRYPOINT ["dotnet", "Consequence.React.dll"]

任何想法,问题,请发表评论.预先谢谢你.

Any ideas, questions, please comment. Thank you in advance.

我终于通过使用isolation = process解决了这个问题.我以为我在使用Hyper-V时遇到了很多麻烦,可以不用它来解决.我关注了文章没有Hyper-V的Windows上的Docker 由Chris进行,并更新了我的 docker hub测试存储库.我还在那里放置了有关如何使其工作的说明.请.现在,我有了Docker映像,可以用作我将来使用Windows Containers进行Docker-React-Redux Docker部署的基础映像.希望这对像我一样遇到过同样问题的人有所帮助.

I finally solved this problem by using isolation=process. I thought I've got so much trouble with Hyper-V and can do without it. I followed the article Docker on Windows without Hyper-V by Chris and updated my docker hub test repo. I also put the instructions there on how to make it work. Please check this out. I now have docker images I can use as a base image for my future Docker-React-Redux docker deployment using Windows Containers. I hope this helps those who have encountered the same problems like me.