I'm trying to deploy XRAY as a sidecar-container of my main container in AWS ECS Fargate using docker-compose; but it creates 2 tasks (Service and Xray) instead of 1 task containing both, the service and the xray daemon.
I have done this in the past without issues using cfn but I cannot make it work with docker-compose.
This is my docker-compose file:
version: "3.9"
services:
web:
image: link-to-private-repo/web
ports: ["80:80"]
xray:
image: amazon/aws-xray-daemon
ports:
- 2000:2000/udp
Thanks.
This is not possible today with the current Docker Compose out of the box experience. This need is tracked in this GH issue. Please weigh in in the issue with your use case.
Related
I'm trying to deploy a docker container with multiple services to ECS. I've been following this article which looks great: https://aws.amazon.com/blogs/containers/deploy-applications-on-amazon-ecs-using-docker-compose/
I can get my container to run locally, and I can connect to the ECS context using the AWS CLI; however in the basic example from the article when I run
docker compose up
In order to deploy the image to ECS, I get the error:
pull access denied, repository does not exist or may require authorization: server message: insufficient_scope: authorization failed
Can't seem to make heads or tails of this. My docker is logged in to ECS using
aws ecr get-login-password --region region | docker login --username AWS --password-stdin aws_account_id.dkr.ecr.region.amazonaws.com
The default IAM user on my aws CLI has AmazonECS_FullAccess as well as "ecs:ListAccountSettings" and "cloudformation:ListStackResources"
I read here: pull access denied repository does not exist or may require docker login mikemaccana 's answer that after Nov 2020 authentication may be required in your YAML file to allow AWS to pull from hub.docker.io (e.g. give aws your Docker hub username and password) but I can't get the 'auth' syntax to work in my yaml file. This is my YAML file that runs tomcat and mariadb locally:
version: "2"
services:
database:
build:
context: ./tba-database
image: tba-database
# set default mysql root password, change as needed
environment:
MYSQL_ROOT_PASSWORD: password
# Expose port 3306 to host. Not for the application but
# handy to inspect the database from the host machine.
ports:
- "3306:3306"
restart: always
webserver:
build:
context: ./tba-webserver
image: tba-webserver
# mount point for application in tomcat
volumes:
- ./target/testPROJ:/usr/local/tomcat/webapps/ROOT
links:
- database:tba-database
# open ports for tomcat and remote debugging
ports:
- "8080:8080"
- "8000:8000"
restart: always
Author of the blog here (thanks for the kind comment!). I haven't played much with the build side of things but I suspect what's happening here is that when you run docker compose up we ignore the build phase and only leverage the image field. What happens next is that the containers being deployed on ECS/Fargate tries to pull the image tba-database (which is where the deploying seems to be complaining because it doesn't exist). You need extra steps to push your image to either GH or ECR before you could bring it life using docker compose up when in the ecs context.
You also probably need to change the compose version ("2" is very old).
I have a docker-compose yml file. It contains 11 services/sections. I am able to successfully deploy it on Ubuntu EC2 instance.
Now, I need to host each service/ section from Docker Compose inside AWS ECS. As per my understanding, I need to create a task definition from AWS ECS UI. I can look at my docker-compose file for image details, environment variables, labels, and just add it inside the task definition. Then, start the task. Now, my ECS tasks should work without any additional settings.
Is this a correct understanding that any service/section docker-compose yml file is ECS compatible?
To my understanding, ECS still doesn't allow the build command in docker-compose.yml so you will run into some headaches.
You can build separate images on ECR and have your docker-compose file to run those when you are creating your services. Don't forget to rebuild those images when you are deploying new code.
Sample docker-compose file
version: '3'
services:
web:
container_name: web
image: some_repository/web:latest
db:
container_name: db
image: some_other_repo/db:latest
Hope this helps.
I currently have a Redis, Postgres and a few Golang containers in a project of mine. I've got it all working locally on my machine using docker-compose.
redis:
container_name: redis
build:
context: .
dockerfile: redis/Dockerfile
ports:
- 6379:6379
networks:
- my-network
This allows me in my Golang microservice to use the container name to connect to the Redis container:
&redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "redis:6379")
},
This all works perfectly, however, I want to place these containers within ECR and use ECS. I'm a bit confused as to how to identify my services and communicate with them in AWS. If I set the namespace to say example and then the service discovery name to redis_service within the ECS service is it as simple as using:
&redis.Pool{
Dial: func() (redis.Conn, error) {
return redis.Dial("tcp", "example.redis_service:6379")
},
Any help would be appreciated!
After linking your containers you will be able to create connection between them the same way like it is done when setting it with docker-compose. It is described in AWS documentation for Dockerrun.aws.json v2
links List of containers to link to. Linked containers can discover each other and communicate securely.
That is if you are using Multicontainer Docker.
For more advanced/manual usage of ECS you may also be interested in this blog post
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?)
You can place both container in same task definitons they will automatically linked with each other.
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".
I am using AWS ECS to run Docker-based tasks. Since ECS agent task definitions don't support all Docker options, I'm looking for some workaround to pass these options to the docker run command.
Is it possible to pass Docker options like --memory-swappiness, --memory-swap, etc. using Dockerfiles?
You should use something like docker compose for that. Docker compose allows to specify parameters for you containers. In contrast Dockerfile configures your image. For example to limit resources you just create resources section in you compose.yml. Note that swappiness is an obsolete parameter.
See link: https://docs.docker.com/compose/compose-file/#resources
version: '3'
services:
redis:
image: redis:alpine
deploy:
resources:
limits:
cpus: '0.50'
memory: 50M
reservations:
cpus: '0.25'
memory: 20M