Azure实例容器:容器连接问题

时间:2020-05-18 19:56:42

标签: azure docker azure-container-instances

我目前正在尝试在Azure容器实例上创建一个新容器,以使用Nginx映像在其上部署有角度的应用程序前端。

我已经在Azure上创建了一个Container Registry,并在其上推送了一个映像(来自本地Docker)。

此应用程序与后端通信。在本地,我将web.config配置为设置后端服务器,然后运行容器。工作

天蓝色,当我创建容器时,我的应用程序未与后端连接(我创建了到后端的端口转发)

这是前端应用程序中web.config的配置:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="ToBack" stopProcessing="true">
          <match url="rc/(.*)" />
          <action type="Rewrite" url="http://X.Y.W.Z:6555/api/{R:1}" logRewrittenUrl="true" />
          <conditions>
          </conditions>
        </rule>
        <rule name="AngularIndex" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Rewrite" url="./index.html" />
        </rule>
      </rules>
    </rewrite>
    <httpErrors errorMode="Detailed" />
  </system.webServer>
  <location path="index.html">
    <system.webServer>
      <staticContent>
        <clientCache cacheControlMode="DisableCache" />
      </staticContent>
    </system.webServer>
  </location>

</configuration>

和Dockerfile:

FROM nginx:stable-alpine

EXPOSE 80

COPY nginx.conf /etc/nginx/nginx.conf

WORKDIR /usr/share/nginx/html

COPY dist/ .

当我从ACI控制台录制curl http://X.Y.W.Z:6555时,我从后端得到响应。

有什么办法解决吗?

2 个答案:

答案 0 :(得分:0)

要允许在ACI中运行的容器从网络访问其他资源,您将需要为容器配置专用的vnet /子网。这样一来,您的容器就可以通过私有IP来访问后端实例,而不用尝试进行端口转发黑客攻击。

参考:

https://docs.microsoft.com/en-us/azure/container-instances/container-instances-overview#virtual-network-deployment

https://docs.microsoft.com/en-us/azure/container-instances/container-instances-vnet

答案 1 :(得分:0)

我忘了Nginx的配置是我自己的

现在可以正常工作

感谢所有人