Я пытаюсь создать определение задачи для приложения nodejs, подключенного к redis.Я пробовал несколько разных определений задач, но когда я запускаю их в своем кластере, все они терпят неудачу, потому что мое приложение не может подключиться к redis.Мое определение задачи, выходные данные журнала, docker-compose.yml, из которого я основываю свою задачу, и мой файл api dockerfile перечислены ниже.
task def
{
"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)
журнал контейнеров Redis
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:
nodejs dockerfile
# 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"]