【问题标题】:Nginx Docker AWS, Nginx is not able to resolve 127.0.0.11 in multi containerNginx Docker AWS,Nginx 无法在多容器中解析 127.0.0.11
【发布时间】:2018-09-26 05:58:59
【问题描述】:

我在做什么:

nginx-openresty 与 mecached 和 docker-compose.

从 nginx 我可以通过指定解析器 = 127.0.0.11 来连接 memcached 容器,在 docker 中编写它的工作文件。

但是当我在 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

DOCKERRUN.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
        }
      ]
    }
  ]
}

【问题讨论】:

    标签: docker nginx docker-compose amazon-elastic-beanstalk openresty


    【解决方案1】:

    你有一个错字: memc:connect("memcache", 11211)

    应该是 memc:connect("memcached", 11211)

    (您缺少一个“d”)。

    【讨论】:

    • 更正了 .json 文件。在这里添加是错误的
    • @sandeep 你得到同样的错误吗? failed to connect: memcache could not be resolved (110: Operation timed out
    • 你可以重建图像
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-13
    • 2019-12-24
    • 1970-01-01
    • 2018-02-13
    • 1970-01-01
    • 2019-06-09
    • 2018-11-10
    相关资源
    最近更新 更多