14

We have an application that uses docker compose that contains links.

I'm trying to deploy this using aws-cli on Amazon Fargate using this command:

ecs-cli compose --project-name myApp --file docker-compose-aws.yml --ecs-params fargate-ecs-params.yml --cluster myCluster --region us-east-1 up --launch-type FARGATE

When my fargate-ecs-params.yml has ecs_network_mode: awsvpc I get the error: Links are not supported when networkMode=awsvpc

So I've tried changing to ecs_network_mode: awsvpc, however I then get the error: Fargate only supports network mode ‘awsvpc’

My question is how do I create a task definition for Fargate with a compose file that contains links? Or is this not possible (and in that case then what are my alternatives?)

tomwilding
  • 303
  • 4
  • 11
  • Post your yml file also – Tarun Lalwani Jan 19 '18 at 15:29
  • Thanks @TarunLalwani I've uploaded the [```docker-compose-aws.yml``` here](https://gist.github.com/tomwilding/2abd38bcf2bcb33b1dd8cd4f61c2181f) – tomwilding Jan 22 '18 at 09:05
  • Please remove `links: - mongo:mongo` and then try. Also `volumes_from` is no more supported in docker compose v3. You should look not to use it – Tarun Lalwani Jan 22 '18 at 09:06
  • Thanks @TarunLalwani, However if I don't use the links then how will the containers connect to each-other? Also we were using a v3 docker-compose file that doesn't use ```volumes_from``` however it seems that AWS ECS doesn't support v3 and so we had to convert it back to v2 – tomwilding Jan 22 '18 at 09:10
  • When trying to use the v3 docker-compose file I get the following error: ```ERRO[0000] Could not parse config for project afp4mule : yaml: unmarshal errors: line 1: cannot unmarshal !!str `3` into config.RawService ERRO[0000] Unable to open ECS Compose Project error="yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `3` into config.RawService" FATA[0000] Unable to create and read ECS Compose Project error="yaml: unmarshal errors:\n line 1: cannot unmarshal !!str `3` into config.RawService"``` – tomwilding Jan 22 '18 at 09:15
  • I think this post probably explains why the links are not supported - docker has deprecated them https://stackoverflow.com/questions/39173670/are-docker-links-deprecated – tomwilding Jan 22 '18 at 09:21
  • Does it work with v2 and no links? – Tarun Lalwani Jan 22 '18 at 11:08
  • @TarunLalwani, it tries to provision the containers, however after a while it deprovisions them... Not sure how to debug the issue because one it deprovisions them the containers are gone - e.g. Can't ssh in or access the logs etc... – tomwilding Jan 31 '18 at 10:42
  • In cloudwatch I can see there are errors in the app startup because it can't access mongo - ```SEVERE: Application startup failed``` ```Caused by: com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches``` – tomwilding Jan 31 '18 at 10:45
  • After investigating further, this was because mongo was not created correctly... looking into the cloudwatch logs for mongo I can see that it fails to start because in the docker compose we have 3 mongo containers. The mongo container that runs the mongo command to create a user fails because the core mongo container has not yet been initialised - this is because we do not have the links! So my question now is how to tell Fargate to create the mongoClient container because the core mongo container, and also to create all the mongo containers before the application container. – tomwilding Jan 31 '18 at 11:37
  • Really useful for me https://stackoverflow.com/questions/47637588/linking-container-in-aws-fargate – Gonzalo Bahamondez Feb 13 '18 at 02:35

2 Answers2

2

You can place both container in same task definitons they will automatically linked with each other.

0

After reading your final comment on the boot sequence and answering that question instead, I solved this (even in non-AWS) using the docker-compose depends.

Simple e.g.

services:
  web:
    depends_on:
      - "web_db"
  web_db:
    image: mongo:3.6
    container_name: my_mongodb

You should be able to remove the deprecated links and just use the hostnames that docker creates from the service container names. e.g. above the website would connect to the hostname: "my_mongodb".

scipilot
  • 6,681
  • 1
  • 46
  • 65