2017-07-24 241 views
1

我正在將我工作的公司的基礎架構的一部分遷移到Amazon ECS,並且我試圖將我的服務器容器連接到數據庫容器。AWS ECS未鏈接我的容器

我繼承人如何設置它在我的任務:

{ 
    "requiresAttributes": [ 
    { 
     "value": null, 
     "name": "com.amazonaws.ecs.capability.docker-remote-api.1.17", 
     "targetId": null, 
     "targetType": null 
    }, 
    { 
     "value": null, 
     "name": "com.amazonaws.ecs.capability.logging-driver.syslog", 
     "targetId": null, 
     "targetType": null 
    }, 
    { 
     "value": null, 
     "name": "com.amazonaws.ecs.capability.docker-remote-api.1.18", 
     "targetId": null, 
     "targetType": null 
    }, 
    { 
     "value": null, 
     "name": "com.amazonaws.ecs.capability.ecr-auth", 
     "targetId": null, 
     "targetType": null 
    } 
    ], 
    "taskDefinitionArn": "arn:aws:ecs:us-east-1:9621234232917455:task-definition/ecv-server:12", 
    "networkMode": "bridge", 
    "status": "ACTIVE", 
    "revision": 12, 
    "taskRoleArn": null, 
    "containerDefinitions": [ 
    { 
     "volumesFrom": [], 
     "memory": 500, 
     "extraHosts": null, 
     "dnsServers": [], 
     "disableNetworking": null, 
     "dnsSearchDomains": null, 
     "portMappings": [], 
     "hostname": "db", 
     "essential": true, 
     "entryPoint": null, 
     "mountPoints": [ 
     { 
      "containerPath": "/var/lib/postgresql/data", 
      "sourceVolume": "dbdata", 
      "readOnly": null 
     } 
     ], 
     "name": "db", 
     "ulimits": null, 
     "dockerSecurityOptions": null, 
     "environment": [ 
     { 
      "name": "POSTGRES_PASSWORD", 
      "value": "jmbrito" 
     }, 
     { 
      "name": "POSTGRES_USER", 
      "value": "jmbrito" 
     } 
     ], 
     "links": [], 
     "workingDirectory": null, 
     "readonlyRootFilesystem": null, 
     "image": "postgres", 
     "command": null, 
     "user": null, 
     "dockerLabels": null, 
     "logConfiguration": { 
     "logDriver": "syslog", 
     "options": null 
     }, 
     "cpu": 0, 
     "privileged": null, 
     "memoryReservation": null 
    }, 
    { 
     "volumesFrom": [], 
     "memory": 400, 
     "extraHosts": null, 
     "dnsServers": [], 
     "disableNetworking": null, 
     "dnsSearchDomains": null, 
     "portMappings": [], 
     "hostname": "redis", 
     "essential": true, 
     "entryPoint": null, 
     "mountPoints": [ 
     { 
      "containerPath": "/data", 
      "sourceVolume": "redisdata", 
      "readOnly": null 
     } 
     ], 
     "name": "redis", 
     "ulimits": null, 
     "dockerSecurityOptions": null, 
     "environment": [], 
     "links": null, 
     "workingDirectory": null, 
     "readonlyRootFilesystem": null, 
     "image": "redis:3.2-alpine", 
     "command": [ 
     "redis-server" 
     ], 
     "user": null, 
     "dockerLabels": null, 
     "logConfiguration": { 
     "logDriver": "syslog", 
     "options": null 
     }, 
     "cpu": 0, 
     "privileged": null, 
     "memoryReservation": null 
    }, 
    { 
     "volumesFrom": [], 
     "memory": 600, 
     "extraHosts": null, 
     "dnsServers": null, 
     "disableNetworking": null, 
     "dnsSearchDomains": null, 
     "portMappings": [ 
     { 
      "hostPort": 80, 
      "containerPort": 3000, 
      "protocol": "tcp" 
     } 
     ], 
     "hostname": null, 
     "essential": true, 
     "entryPoint": [], 
     "mountPoints": [], 
     "name": "server", 
     "ulimits": null, 
     "dockerSecurityOptions": null, 
     "environment": [ 
     { 
      "name": "RAILS_ENV", 
      "value": "production" 
     } 
     ], 
     "links": [ 
     "db:db", 
     "redis:redis" 
     ], 
     "workingDirectory": "/usr/src/app", 
     "readonlyRootFilesystem": null, 
     "image": "MY DOCKER LINK IN ECR", 
     "command": [ 
     "sh", 
     "deploy/init.sh" 
     ], 
     "user": null, 
     "dockerLabels": null, 
     "logConfiguration": { 
     "logDriver": "syslog", 
     "options": null 
     }, 
     "cpu": 0, 
     "privileged": null, 
     "memoryReservation": null 
    } 
    ], 
    "placementConstraints": [], 
    "volumes": [ 
    { 
     "host": { 
     "sourcePath": null 
     }, 
     "name": "dbdata" 
    }, 
    { 
     "host": { 
     "sourcePath": null 
     }, 
     "name": "redisdata" 
    } 
    ], 
    "family": "ecv-server" 
} 

正如你可以看到我正確設置我的連接字段,當我嘗試使用名稱,如連接到主機數據庫或主機redis的連接它沒有找到它。

我嘗試使用VPC地址連接到其他容器,它的工作。唯一的問題是,爲了做到這一點,我最好自己設置VPC中的地址(比如將172.13.0.2設置爲db),因爲當我不設置時,系統通過連接順序獲取地址。

我希望你能理解這個問題。

謝謝。

回答

1

我不認爲這個任務定義會按照你想要的方式工作。當您將三個容器放入一個任務定義中時,它會告訴ECS始終將這三個容器一起部署在同一臺機器上,每次部署任務時。

因此,如果您爲此任務部署的服務的期望計數爲3,您將獲得三個應用容器,三個postgres容器和三個redis容器。這三個應用程序容器將有三個獨立的數據持久性堆棧。應用程序容器A將僅與postgres A和redis A進行通信,而應用程序容器B將僅與postgress B和redis B進行通信,因此每個應用程序容器將具有不相互複製的不一致數據。

在任務定義中運行多個容器實際上僅用於邊車容器,例如反向代理或臨時緩存或類似容器。

對於持久層,我的建議是使用Amazon RDS作爲您的postgres,Amazon Elasticache作爲您的redis。通過這種方式,您的所有任務都可以共享相同的postgres和相同的redis,並且您還可以通過使用這些Amazon服務減少很多管理操作。