Guillaume
Guillaume

Reputation: 586

How to launch my docker container automatically on ECS?

How can I launch automatically my docker container on ECS (Amazon Web Service) ? When my EC2 instance is ready, i want to launch this command :

docker run -d -p 80:80 myusername/mydocker /usr/sbin/apache2ctl -D FOREGROUND

on my EC2 to launch automatically (without SSH) my container.

Can you help me ?

Upvotes: 3

Views: 780

Answers (2)

Guillaume
Guillaume

Reputation: 586

I finally found the solution !

On ECS you have to add a entrypoint and not command.

So if you want to launch your docker container when the EC2 is ready, you can use this sample :

{
  "family": "familyName",
  "containerDefinitions": [
    {
      "name": "testSample",
      "image": "usernameDocker/containerName",
      "cpu": 1,
      "memory": 500,
      "entryPoint": [
        "/usr/sbin/apache2ctl",
        "-D",
        "FOREGROUND"
      ],
      "environment": [],
      "command": [],
      "portMappings": [
        {
          "hostPort": 80,
          "containerPort": 80,
          "protocol": "tcp"
        },
        {
          "hostPort": 2222,
          "containerPort": 22,
          "protocol": "tcp"
        }
      ],
      "volumesFrom": [],
      "links": [],
      "mountPoints": [],
      "essential": true
    }
  ],
  "volumes": []
}

Regards,

Upvotes: 4

Sachin Malhotra
Sachin Malhotra

Reputation: 1251

Why not write a bash script having this command and add the command to run that bash script in your .bashrc / .bashprofile so that it gets executed on startup. I am telling you to write a bash file so that in future you can also add some more commands which you want to run on startup.

Upvotes: 1

Related Questions