【问题标题】:Unable to connect redis container from my web api container in azure container instance(ACI)无法在 Azure 容器实例(ACI)中从我的 Web api 容器连接 redis 容器
【发布时间】:2020-11-08 17:54:33
【问题描述】:

我在 azure 容器实例(容器组)中部署我的应用程序。

我有 3 个 docker 容器

  • web_api
  • redis
  • neo4j

我可以使用localhost:7474 作为主机名来访问数据库,但是不能使用localhost 作为主机名来访问redis。 当我使用 docker run 命令在本地运行容器时,我遇到了同样的问题。

注意:我不能使用 docker-compose,因为我打算使用 ACI。

azuredeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "containerGroupName": {
      "type": "string",
      "defaultValue": "devCG",
      "metadata": {
        "description": ""
      }
    }
  },
  "variables": {
    "name_web": "web-api",
    "image_web": "dev.azurecr.io/web-api:89",
    "name_redis": "redis",
    "image_redis": "redis:5.0.9",
    "name_neo4j": "neo4j",
    "image_neo4j": "neo4j:3.5.6"
  },
  "resources": [
    {
      "name": "[parameters('containerGroupName')]",
      "type": "Microsoft.ContainerInstance/containerGroups",
      "apiVersion": "2019-12-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "containers": [
          {
            "name": "[variables('name_web')]",
            "properties": {
              "image": "[variables('image_web')]",
              "resources": {
                "requests": {
                  "cpu": 1,
                  "memoryInGb": 0.5
                }
              },
              "ports": [
                {
                  "port": 80
                },
                {
                  "port": 8080
                }
              ]
            }
          },
          {
            "name": "[variables('name_redis')]",
            "properties": {
              "image": "[variables('image_redis')]",
              "resources": {
                "requests": {
                  "cpu": 0.5,
                  "memoryInGb": 0.2
                }
              }
            }
          },
          {
            "name": "[variables('name_neo4j')]",
            "properties": {
              "image": "[variables('image_neo4j')]",
              "resources": {
                "requests": {
                  "cpu": 0.5,
                  "memoryInGb": 0.2
                }
              },
              "ports": [
                {
                  "port": 7474
                }
              ]
            }
          }
        ],
        "imageRegistryCredentials": [
          {
            "server": "dev.azurecr.io",
            "username": "dev",
            "password": "********************"
          }
        ],
        "restartPolicy": "Always",
        "osType": "Linux",
        "volumes": [
          {
            "name": "devfs",
            "azureFile": {
              "shareName": "dev",
              "readOnly": "false",
              "storageAccountName": "devfs",
              "storageAccountKey": "*****************************"
            }
          }
        ],
        "ipAddress": {
          "type": "Public",
          "ports": [
            {
              "protocol": "tcp",
              "port": 80
            }
          ],
          "dnsNameLabel": "dev"
        }
      }
    }
  ],
  "outputs": {
    "containerIPv4Address": {
      "type": "string",
      "value": "[reference(resourceId('Microsoft.ContainerInstance/containerGroups/', parameters('containerGroupName'))).ipAddress.ip]"
    }
  }
}

【问题讨论】:

    标签: docker redis azure-container-instances


    【解决方案1】:

    通过本地主机访问 redis 需要在 redis 配置中进行特殊调整。

    看看

    https://github.com/docker-library/redis/issues/45

    https://github.com/luin/ioredis/issues/763

    建议通过 redis 主机名连接,您可以将这个本地小睡到 redis 主机名

    【讨论】:

    • 如上述文章和redis.io/topics/quickstart 中所建议,我提供了command": ["redis-server", "--bind", "127.0.0.1", "--port", "6379"]。但我仍然收到[ioredis] Unhandled error event: Error: connect ECONNREFUSED 127.0.0.1:6379
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    • 2020-02-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多