Reputation: 379
I mounted EBS to ecs-enabled instance in AWS.
For EBS to be visible to docker, docker daemon has to be restarted. I added appropriate commands to the user-data. But I am unable to restart ecs-agent docker container from the user data.
Following is my user-data:
#!/bin/bash
echo ECS_CLUSTER=MYCLUSTER>> /etc/ecs/ecs.config
mkfs -t ext4 /dev/sdb
mkdir /db/
mount /dev/sdb /db/
service docker stop
service docker start
docker start ecs-agent
On SSH, I could see that the ecs-agent container is created but it is not running. When I start the container manually, it is working. What is the correct way to start it during instance launch? What am I missing in my user-data script?
I need to create a launch configuration for use in my auto-scaling group. Instances should have EBS enabled and visible to docker.
Upvotes: 1
Views: 12365
Reputation: 1165
If you need to restart the Docker daemon, it seems likely that you're dealing with an existing EC2 instance. In that case, user data scripts won't help you because according to the EC2 User Guide they "only run during the first boot cycle when an instance is launched".
As for the correct way to start the ECS agent during instance launch, it depends on which distribution you're running. For Amazon Linux instances the ECS Developer Guide recommends the ecs-init
package:
sudo yum install -y ecs-init
sudo service docker start
sudo start ecs
(If you put this in your user data scripts, do not use sudo
.)
Upvotes: 8