VS React-Redux 容器连接到 api-sqlserver 容器 [英] VS React-Redux container connecting to api-sqlserver containers

查看:17
本文介绍了VS React-Redux 容器连接到 api-sqlserver 容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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. 我设法使 api 连接到 sqlserver 并通过创建 docker nat 网络使它们通信.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.

React 项目 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 时遇到了很多麻烦,没有它也可以.我关注了文章 Windows 上没有 Hyper-V 的 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.

这篇关于VS React-Redux 容器连接到 api-sqlserver 容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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