ローカルでは問題なく起動できますが、ecrにimageをpush後、fargate内で
ruby
1/usr/local/bundle/gems/puma-4.3.8/lib/puma/binder.rb:229:in `initialize': getaddrinfo: Name or service not known (SocketError)
上記エラーが発生します。これはcloudwatch logsから確認しています。
ネット記事だとこのようなエラーはあまり起きていないようで、
海外のサイトだと/etc/hostsに host名を記述しろと書いてありますが、rails6にそのようなファイルは生成されないと認識しております。
ruby
1# development.rb 2config.hosts << "api_container" #タスク定義内のコンテナ名
を記述したところpumaの起動の様子が変わって2~3回起動を試みた後に、結局同じSocketErrorが出現しました。
解決方法のご教授よろしくお願い致します。
追記です。
terraformで構築しております。
docker
1# /api/Dockerfile 2 3FROM ruby:2.7.1 4 5 6ENV RAILS_ENV production 7EXPOSE 3000 8 9RUN apt-get update -qq && \ 10 apt-get install -y build-essential \ 11 libpq-dev \ 12 nodejs \ 13 && rm -rf /var/lib/apt/lists/* 14 15RUN mkdir /app 16WORKDIR /app 17 18 19COPY . . 20 21RUN bundle install
json
1// terraform/definitions/container.json 2[ 3 { // フロントの定義の為省略 4 }, 5 { 6 "name": "api_container", 7 "image": "1234567765432(例).dkr.ecr.ap-northeast-1.amazonaws.com/api:latest", 8 "essential": true, 9 "logConfiguration": { 10 "logDriver": "awslogs", 11 "options": { 12 "awslogs-region": "ap-northeast-1", 13 "awslogs-stream-prefix": "api", 14 "awslogs-group": "/ecs/api" 15 } 16 }, 17 "portMappings": [ 18 { 19 "protocol": "tcp", 20 "containerPort": 3000 21 } 22 ], 23 "environment": [ 24 { 25 "name": "HOST", 26 "value": "0.0.0.0" 27 }, 28 { 29 "name": "PORT", 30 "value": "3000" 31 }, 32 { 33 "name": "RAILS_ENV", 34 "value": "production" 35 } 36 ], 37 "secrets": [ 38 { 39 "name": "API_DOMAIN", 40 "valueFrom": "API_DOMAIN" 41 }, 42 { 43 "name": "DATABASE_URL", 44 "valueFrom": "DATABASE_URL" 45 }, 46 { 47 "name": "RAILS_MASTER_KEY", 48 "valueFrom": "RAILS_MASTER_KEY" 49 } 50 ], 51 "command": [ 52 "bundle", 53 "exec", 54 "rails", 55 "s", 56 "-b", 57 "'0.0.0.0'", 58 "-p", 59 "3000" 60 ] 61 } 62]
json
1//タスク定義 2// terraform/ecs.tf 3resource "aws_ecs_task_definition" "nurse_container" { 4 family = "nurse_container" 5 cpu = "512" 6 memory = "1024" 7 network_mode = "awsvpc" 8 requires_compatibilities = ["FARGATE"] 9 container_definitions = file("./definitions/nurse_container.json") 10 execution_role_arn = module.ecs_task_execution_role.iam_role_arn 11}
json
1resource "aws_ecs_service" "nurse" { 2 name = "nurse" 3 cluster = aws_ecs_cluster.cluster.arn 4 task_definition = aws_ecs_task_definition.nurse_container.arn 5 desired_count = 1 6 launch_type = "FARGATE" 7 platform_version = "1.4.0" 8 health_check_grace_period_seconds = 60 9 10 network_configuration { 11 assign_public_ip = false 12 security_groups = [ 13 module.front_sg.security_group_id, 14 module.api_sg.security_group_id 15 ] 16 17 subnets = [ 18 aws_subnet.private-1a.id, 19 aws_subnet.private-1c.id 20 ] 21 } 22 23 load_balancer { 24 target_group_arn = aws_lb_target_group.front_container.arn 25 container_name = "front_container" 26 container_port = 8080 27 } 28 29 lifecycle { 30 ignore_changes = [task_definition] 31 } 32}
json
1// セキュリティグループ 2// terraform/sg.tf 3 4module "http_sg" { 5 source = "./security_group" 6 name = "http_sg" 7 vpc_id = aws_vpc.vpc.id 8 port = 80 9 cidr_blocks = ["0.0.0.0/0"] 10} 11 12module "https_sg" { 13 source = "./security_group" 14 name = "https_sg" 15 vpc_id = aws_vpc.vpc.id 16 port = 443 17 cidr_blocks = ["0.0.0.0/0"] 18} 19 20module "front_sg" { 21 source = "./security_group" 22 name = "front_sg" 23 vpc_id = aws_vpc.vpc.id 24 port = 8080 25 cidr_blocks = [aws_vpc.vpc.cidr_block] 26} 27 28module "api_sg" { 29 source = "./security_group" 30 name = "api_sg" 31 vpc_id = aws_vpc.vpc.id 32 port = 3000 33 cidr_blocks = [aws_vpc.vpc.cidr_block] 34}
回答1件
あなたの回答
tips
プレビュー