Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.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

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
Amazon web services 在amazon ecs任务定义中,Nodejs应用程序未连接到redis。getaddrinfo ENOTFOUND redis redis:6379_Amazon Web Services_Docker_Redis_Amazon Ecs - Fatal编程技术网

Amazon web services 在amazon ecs任务定义中,Nodejs应用程序未连接到redis。getaddrinfo ENOTFOUND redis redis:6379

Amazon web services 在amazon ecs任务定义中,Nodejs应用程序未连接到redis。getaddrinfo ENOTFOUND redis redis:6379,amazon-web-services,docker,redis,amazon-ecs,Amazon Web Services,Docker,Redis,Amazon Ecs,我正在尝试为连接到redis的nodejs应用程序创建任务定义。我尝试了几种不同的任务定义,但当我在集群中运行它们时,它们都失败了,因为我的应用程序无法连接到redis。下面列出了我的任务定义、日志输出、基于任务定义的docker-compose.yml和api dockerfile 任务定义 { "ipcMode": null, "executionRoleArn": "arn:aws:iam::210939474461:role/ecsTaskExecutionRole", "c

我正在尝试为连接到redis的nodejs应用程序创建任务定义。我尝试了几种不同的任务定义,但当我在集群中运行它们时,它们都失败了,因为我的应用程序无法连接到redis。下面列出了我的任务定义、日志输出、基于任务定义的docker-compose.yml和api dockerfile

任务定义

{
  "ipcMode": null,
  "executionRoleArn": "arn:aws:iam::210939474461:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "dnsSearchDomains": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "secretOptions": null,
        "options": {
          "awslogs-group": "/ecs/rest-api-explorer",
          "awslogs-region": "us-west-2",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "entryPoint": null,
      "portMappings": [
        {
          "hostPort": 0,
          "protocol": "tcp",
          "containerPort": 3000
        },
        {
          "hostPort": 0,
          "protocol": "tcp",
          "containerPort": 6379
        }
      ],
      "command": null,
      "linuxParameters": null,
      "cpu": 0,
      "environment": [
        {
          "name": "redis_server_addr",
          "value": "redis"
        }
      ],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memory": null,
      "memoryReservation": 128,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "210939474461.dkr.ecr.us-west-2.amazonaws.com/rest-api-explorer",
      "startTimeout": null,
      "dependsOn": [
        {
          "containerName": "redis",
          "condition": "START"
        }
      ],
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": null,
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null,
      "name": "api-rest-explorer"
    },
    {
      "dnsSearchDomains": null,
      "logConfiguration": {
        "logDriver": "awslogs",
        "secretOptions": null,
        "options": {
          "awslogs-group": "/ecs/rest-api-explorer",
          "awslogs-region": "us-west-2",
          "awslogs-stream-prefix": "ecs"
        }
      },
      "entryPoint": null,
      "portMappings": [
        {
          "hostPort": 0,
          "protocol": "tcp",
          "containerPort": 6379
        }
      ],
      "command": null,
      "linuxParameters": null,
      "cpu": 0,
      "environment": [],
      "resourceRequirements": null,
      "ulimits": null,
      "dnsServers": null,
      "mountPoints": [],
      "workingDirectory": null,
      "secrets": null,
      "dockerSecurityOptions": null,
      "memory": null,
      "memoryReservation": null,
      "volumesFrom": [],
      "stopTimeout": null,
      "image": "redis",
      "startTimeout": null,
      "dependsOn": null,
      "disableNetworking": null,
      "interactive": null,
      "healthCheck": null,
      "essential": true,
      "links": null,
      "hostname": null,
      "extraHosts": null,
      "pseudoTerminal": null,
      "user": null,
      "readonlyRootFilesystem": null,
      "dockerLabels": null,
      "systemControls": null,
      "privileged": null,
      "name": "redis"
    }
  ],
  "placementConstraints": [],
  "memory": "1024",
  "taskRoleArn": "arn:aws:iam::210939474461:role/ecsTaskExecutionRole",
  "compatibilities": [
    "EC2"
  ],
  "taskDefinitionArn": "arn:aws:ecs:us-west-2:210939474461:task-definition/rest-api-explorer:8",
  "family": "rest-api-explorer",
  "requiresAttributes": [
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.container-ordering"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-ecr-pull"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.ecr-auth"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.task-iam-role"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "ecs.capability.execution-role-awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.logging-driver.awslogs"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.21"
    },
    {
      "targetId": null,
      "targetType": null,
      "value": null,
      "name": "com.amazonaws.ecs.capability.docker-remote-api.1.19"
    }
  ],
  "pidMode": null,
  "requiresCompatibilities": [
    "EC2"
  ],
  "networkMode": "bridge",
  "cpu": "128",
  "revision": 8,
  "status": "ACTIVE",
  "proxyConfiguration": null,
  "volumes": []
}
应用程序容器日志

2019-06-12 16:01:06 events.js:183
2019-06-12 16:01:06 throw er; // Unhandled 'error' event
2019-06-12 16:01:06 ^
2019-06-12 16:01:06 Error: Redis connection to redis:6379 failed - getaddrinfo ENOTFOUND redis redis:6379
2019-06-12 16:01:06 at RedisClient.on_error (/var/api-console/node_modules/redis/index.js:148:24)
2019-06-12 16:01:06 at Socket.<anonymous> (/var/api-console/node_modules/redis/index.js:83:14)
2019-06-12 16:01:06 at emitOne (events.js:116:13)
2019-06-12 16:01:06 at Socket.emit (events.js:211:7)
2019-06-12 16:01:06 at emitErrorNT (internal/streams/destroy.js:66:8)
2019-06-12 16:01:06 at _combinedTickCallback (internal/process/next_tick.js:139:11)
2019-06-12 16:01:06 at process._tickCallback (internal/process/next_tick.js:181:9)
2019-06-12 16:01:071:M 12 Jun 2019 23:01:07.216 * DB saved on disk
2019-06-12 16:01:071:M 12 Jun 2019 23:01:07.216 # Redis is now ready to exit, bye bye...
2019-06-12 16:01:071:M 12 Jun 2019 23:01:07.213 # User requested shutdown...
2019-06-12 16:01:071:M 12 Jun 2019 23:01:07.213 * Saving the final RDB snapshot before exiting.
2019-06-12 16:01:071:signal-handler (1560380467) Received SIGTERM scheduling shutdown...
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 * Running mode=standalone, port=6379.
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 # Server initialized
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
2019-06-12 16:01:041:M 12 Jun 2019 23:01:04.400 * Ready to accept connections
docker-compose.yml

version: '3'
services:
  redis:
    image: redis
    expose:
      - "6379"
    command:
      redis-server
    networks:
      - webnet
  app:
    build: ./
    image: rest_api_console
    ports:
      - 3000:3000
    depends_on:
      - redis
    environment:
      redis_server_addr: redis 
    networks:
      - webnet
networks:
  webnet:

nodejsdockerfile

# Use an official Python runtime as a parent image
FROM node:8-jessie

# Set the working directory to /var/api-console
WORKDIR /var/api-console

# Copy api-consol.tar, unpack, and install dependencies
COPY api-console.tar ./
RUN tar -xvf api-console.tar && \
    npm install && \
    apt-get update && \
    apt-get install python

# Modify config.js to replace host:'localhost' with host:'redis'
RUN sed -i -r 's/localhost/redis/g' config.json

# Make port 3000 available to the world outside this container
EXPOSE 3000

# Run app.js when the container launches
CMD ["node", "app.js"]


AWS支持在网桥网络模式下链接,但您的任务定义似乎链接为空

"links": null,
您的redis和nodejs服务器应该位于同一个任务定义中

首先,在同一任务定义中创建redis容器

然后在nodejs服务器中定义链接


很高兴知道它起作用了。
{
"ipcMode": null,
"executionRoleArn": null,
"containerDefinitions": [
    {
        "dnsSearchDomains": null,
        "logConfiguration": null,
        "entryPoint": null,
        "portMappings": [
            {
                "hostPort": 8700,
                "protocol": "tcp",
                "containerPort": 8700
            }
        ],
        "command": null,
        "linuxParameters": null,
        "cpu": 0,
        "environment": [],
        "resourceRequirements": null,
        "ulimits": null,
        "dnsServers": null,
        "workingDirectory": null,
        "secrets": null,
        "dockerSecurityOptions": null,
        "memory": 1000,
        "memoryReservation": 300,
        "volumesFrom": [],
        "stopTimeout": null,
        "image": "****.dkr.ecr.us-west-2.amazonaws.com/stage/nodejs:latest",
        "startTimeout": null,
        "dependsOn": null,
        "disableNetworking": null,
        "interactive": null,
        "healthCheck": null,
        "essential": true,
        "links": [
            "redis"
        ],
        "hostname": null,
        "extraHosts": null,
        "pseudoTerminal": null,
        "user": null,
        "readonlyRootFilesystem": null,
        "dockerLabels": {
            "Name": "nodejs"
        },
        "systemControls": null,
        "privileged": null,
        "name": "nodejs"
    },
    {
        "dnsSearchDomains": null,
        "logConfiguration": null,
        "entryPoint": null,
        "portMappings": [
            {
                "hostPort": 6379,
                "protocol": "tcp",
                "containerPort": 6379
            }
        ],
        "command": null,
        "linuxParameters": null,
        "cpu": 0,
        "environment": [],
        "resourceRequirements": null,
        "ulimits": null,
        "dnsServers": null,
        "mountPoints": [],
        "workingDirectory": null,
        "secrets": null,
        "dockerSecurityOptions": null,
        "memory": 600,
        "memoryReservation": 200,
        "volumesFrom": [],
        "stopTimeout": null,
        "image": "****.dkr.ecr.us-west-2.amazonaws.com/redis:latest",
        "startTimeout": null,
        "dependsOn": null,
        "disableNetworking": null,
        "interactive": null,
        "healthCheck": null,
        "essential": true,
        "links": null,
        "hostname": null,
        "extraHosts": null,
        "pseudoTerminal": null,
        "user": null,
        "readonlyRootFilesystem": null,
        "dockerLabels": null,
        "systemControls": null,
        "privileged": null,
        "name": "redis"
    }
],
"memory": null,
"family": "staging-nodejs-redis",
"pidMode": null,
"requiresCompatibilities": [],
"networkMode": null,
"cpu": null,
"proxyConfiguration": null,


   "placementConstraints": []
}