Search code examples
javaamazon-web-servicesamazon-ec2dockeramazon-ecs

Running multiple docker instances in EC2


I am new to AWS. So please bear with me if my question doesn't make sense.

My goal is to run multiple docker containers(with different docker config) in one AWS EC2 instance. So far I have been able to programatically start and stop EC2 instance using java SDK.

I guess for running docker instances in EC2 I will have to use ECS Api(AmazonECSClient - included in AWS java SDK). Unfortunately there are hardly any examples that I am able to find for this using AWS java SDK.

Does anybody know how to accomplish this? Any pointers would be helpful.


Solution

  • The api documentation here gives a clear enough answer.

    You basically;

    1. Create the docker image locally.
    2. Upload/push to your docker registry (e.g., docker hub)
    3. Specify a task definition including your docker image reference.
    4. Launch your cluster based on the container images specified in your task definition.