By sandeep


2018-04-16 13:14:29 8 Comments

What I am working on:

nginx- openresty with mecached and docker-compose.

from nginx I am able to connect memcached container by specifying resolver = 127.0.0.11, in docker compose it working file.

But when I am deploying it on AWS multi container beanstalk I am getting time out error

failed to connect: memcache could not be resolved (110: Operation timed out)

but from nginx container I am able to 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
        }
      ]
    }
  ]
}

1 comments

@Constantin Galbenu 2018-04-16 13:22:22

You have a typo: memc:connect("memcache", 11211)

should be memc:connect("memcached", 11211)

(you are missing a "d").

@sandeep 2018-04-16 14:50:32

Corrected .json file. it was mistake while adding it in here

@Constantin Galbenu 2018-04-16 14:56:49

@sandeep and you get the same error? failed to connect: memcache could not be resolved (110: Operation timed out

@sandeep 2018-04-16 14:59:26

Yes same error :(

@Constantin Galbenu 2018-04-16 15:03:27

You could rebuild the image

@sandeep 2018-04-16 15:08:47

yes and its deployed in AWS also.

Related Questions

Sponsored Content

19 Answered Questions

[SOLVED] How is Docker different from a virtual machine?

14 Answered Questions

11 Answered Questions

[SOLVED] Node.js + Nginx - What now?

  • 2011-02-15 20:49:02
  • Van Coding
  • 303407 View
  • 854 Score
  • 11 Answer
  • Tags:   node.js nginx concept

13 Answered Questions

[SOLVED] Copying files from Docker container to host

  • 2014-02-26 17:46:52
  • user2668128
  • 365168 View
  • 821 Score
  • 13 Answer
  • Tags:   docker

10 Answered Questions

[SOLVED] How to list containers in Docker

  • 2013-05-30 15:41:46
  • w00t
  • 520111 View
  • 686 Score
  • 10 Answer
  • Tags:   docker

32 Answered Questions

[SOLVED] Copying files from host to Docker container

  • 2014-04-07 08:28:55
  • user3001829
  • 615657 View
  • 861 Score
  • 32 Answer
  • Tags:   docker

52 Answered Questions

[SOLVED] How to remove old Docker containers

  • 2013-06-21 13:41:42
  • qkrijger
  • 607819 View
  • 978 Score
  • 52 Answer
  • Tags:   docker

10 Answered Questions

[SOLVED] Should I use Vagrant or Docker for creating an isolated environment?

  • 2013-05-20 10:05:25
  • murtaza52
  • 362253 View
  • 1876 Score
  • 10 Answer
  • Tags:   vagrant docker

14 Answered Questions

[SOLVED] How to deal with persistent storage (e.g. databases) in docker

  • 2013-08-28 19:45:44
  • juwalter
  • 237218 View
  • 832 Score
  • 14 Answer
  • Tags:   docker

2 Answered Questions

php-fpm & nginx in separated docker container, can not execute .php file

  • 2016-10-11 10:55:20
  • Hacksign
  • 615 View
  • 0 Score
  • 2 Answer
  • Tags:   php nginx docker

Sponsored Content