I'my deploying a simple Compose file with a Flask app server talking to PSQL database in another container; works locally fine.
When using the new-ish Docker Compose deploy to ECS context, it fails: the app server cannot DNS resolve the name of the "psql" server. I see it created a CloudMap with entries for my service name, but to no avail.
Docker version 20.10.8, build 3967b7d
So I followed YELB tutorial by @mreferre (https://aws.amazon.com/de/blogs/containers/deploy-applications-on-amazon-ecs-using-docker-compose/), and it also deployed locally, but failed on "docker compose up":
YelbuiService CREATE_FAILED Resource creation cancelled
I see in his docker-compose.yml this critical note:
networks:
yelb-network:
driver: bridge # a user defined bridge is required; the default bridge network doesn't support name resolution
But everything I've read says that Compose to ECS uses FARGATE, and that requires an awsvpc network, not a bridge. And before it disappeared, the AWS console showed my YELB Tasks were using awsvpc networks, not bridge.
I defined a bridge network in my Flask/PSQL app anyway and did another docker compose up and noticed this (which probably scrolled off my YELB screen):
WARNING networks.driver: unsupported attribute
So it seems awsvpc does NOT support Service Discovery by DNS resolution, and we cannot use bridge for Docker to ECS, so I'm stuck.
Or am I missing something?
Do I have to use the separate ecs-cli tools to deploy my Compose file? It's a lot more hairy than the sweet docker compose up we know and love, and requires me to do a lot more work.
Any other guidance?
Thanks for your help.
My repo in progress is at https://github.com/shentonfreude/compose-ecs-flask-psql
but for convenience the docker-compose.yml is:
version: "3" # ECS may not like decimal suffix"
x-aws-logs_retention: 7
x-aws-vpc: vpc-01234567890123456 # in ue1
networks:
# YELB says: user defined bridge required; default bridge network doesn't support name resolution
flasknet:
driver: bridge
services:
psql:
container_name: psql
image: postgres:9.6.2-alpine
environment:
POSTGRES_USER: flaskapp
POSTGRES_DB: flaskapp
POSTGRES_PASSWORD: flaskapp
healthcheck:
test: "pg_isready --username=flaskapp && psql --username=flaskapp --list"
interval: 5s
timeout: 5s
retries: 5
networks:
- flasknet
flaskapp:
container_name: flaskapp
image: 314159265358.dkr.ecr.us-east-1.amazonaws.com/cshenton/flaskapp:latest
environment:
# Neither bare service "psql",
# FQDN "psql.psql.compose-ecs-flask-psql.local",
# nor awsvpc "localhost" work.
DB_HOST: psql
DB_PORT: 5432
DB_NAME: flaskapp
DB_PASSWORD: flaskapp
DB_USER: flaskapp
ports:
- "80:80"
depends_on:
psql:
condition: service_healthy
deploy:
resources:
limits:
cpus: "0.5"
memory: 512M
networks:
- flasknet