Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Nginx Docker AWS,Nginx无法在多容器中解析127.0.0.11_Docker_Nginx_Docker Compose_Amazon Elastic Beanstalk_Openresty - Fatal编程技术网

Nginx Docker AWS,Nginx无法在多容器中解析127.0.0.11

Nginx Docker AWS,Nginx无法在多容器中解析127.0.0.11,docker,nginx,docker-compose,amazon-elastic-beanstalk,openresty,Docker,Nginx,Docker Compose,Amazon Elastic Beanstalk,Openresty,我正在从事的工作: nginx-openresty与mecached和docker组合 在nginx中,我可以通过在docker compose it工作文件中指定resolver=127.0.0.11来连接memcached容器 但当我在AWS多容器beanstalk上部署它时,我得到了超时错误 failed to connect: memcache could not be resolved (110: Operation timed out) 但从nginx容器中,我可以ping mem

我正在从事的工作:

nginx-openresty与mecached和docker组合

在nginx中,我可以通过在docker compose it工作文件中指定resolver=127.0.0.11来连接memcached容器

但当我在AWS多容器beanstalk上部署它时,我得到了超时错误

failed to connect: memcache could not be resolved (110: Operation timed out)
但从nginx容器中,我可以ping memcahed

NGINX.conf

location /health-check {
  resolver 127.0.0.11 ipv6=off;
  access_by_lua_block {

      local memcached = require "resty.memcached"
      local memc, err = memcached:new()
      if not memc then
          ngx.say("failed to instantiate memc: ", err)
          return
      end

      memc: set_timeout(1000) -- 1 sec

      local ok, err = memc:connect("memcache", 11211)
      if not ok then
          ngx.say("failed to connect: ", err)
          return
      end
DOCKER-COMPOSE.YML

    version: "3"

services:

  memcache:
    image: memcached:alpine
    container_name: memcached
    ports:
      - "11211:11211"
    expose:
      - "11211"
    networks:
      - default


  nginx:
    image: openresty/openresty:alpine
    container_name: nginx
    volumes:
      # Nginx files
      - ./nginx/:/etc/nginx/:ro
      # Web files
      - ./web/:/var/www/web/:ro
    entrypoint: openresty -c /etc/nginx/nginx.conf
    ports:
      - "8080:8080"
    networks:
      - default
dockrun.AWS.JSON

{
  "AWSEBDockerrunVersion": 2,

  "volumes": [
    {
      "name": "current-nginx",
      "host": {
        "sourcePath": "/var/app/current/nginx"
      }
    },
    {
      "name": "web",
      "host": {
        "sourcePath": "/var/www/web/"
      }
    }
  ],
  "containerDefinitions": [
    {
      "name": "memcache",
      "image": "memcached:alpine",
      "essential": true,
      "memory": 1000,
      "portMappings": [
        {
          "hostPort": 11211,
          "containerPort": 11211
        }
      ]
    },
    {
      "name": "nginx",
      "image": "openresty/openresty:alpine",
      "essential": true,
      "memory": 1000,
      "entryPoint": [
        "openresty",
        "-c",
        "/etc/nginx/nginx.conf"
      ],
      "links": [
        "memcache"
      ],

      "portMappings": [

        {
          "hostPort": 8080,
          "containerPort": 8080
        },
        {
          "hostPort": 80,
          "containerPort": 8080
        }
      ],
      "mountPoints": [
        {
          "sourceVolume": "web",
          "containerPath": "/var/www/web/",
          "readOnly": false
        },
        {
          "sourceVolume": "current-nginx",
          "containerPath": "/etc/nginx",
          "readOnly": false
        }
      ]
    }
  ]
}
您有一个输入错误:

memc:connect(“memcache”,11211)

应该是

memc:connect(“memcached”,11211)


(您缺少一个“d”)。

更正的.json文件。把它加进去是个错误here@sandeep你也会犯同样的错误<代码>连接失败:无法解析memcache(110:操作超时)您可以重建映像