Restart ecs-agent from user-data
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-initsudo service docker startsudo start ecs
(If you put this in your user data scripts, do not use sudo
.)