在实例初始化后运行UserData

时间:2016-06-29 15:00:31

标签: amazon-web-services amazon-ec2 amazon-cloudformation

我正在使用cloudformation通过包含docker镜像的AMI创建ec2实例。

想法是使用userData在初始化实例后运行docker镜像。

但是一旦我通过ssh连接并检查docker容器,就没有docker容器正在运行。

这是我的cloudformation模板

     "instancei0755a35a9c753812d": {
  "Type": "AWS::EC2::Instance",
  "Properties": {
    "DisableApiTermination": "false",
    "InstanceInitiatedShutdownBehavior": "stop",
    "ImageId": "ami-foooo",
    "InstanceType": "t2.medium",
    "KeyName": "jenkins_price",
    "Monitoring": "false",
    "Tags": [
      {
        "Key": "Name",
        "Value": "Jenkins"
      },
      {
        "Key": "Type",
        "Value": "jenkins"
      }
    ],
    "Volumes": [
      {
        "Device": "/dev/sdf",
        "VolumeId": {
          "Ref": "volumevolab668c6e"
        }
      }
    ],
    "NetworkInterfaces": [
      {
        "AssociatePublicIpAddress": true,
        "DeleteOnTermination": "true",
        "DeviceIndex": 0,
        "SubnetId": {
          "Ref": "subnet"
        },
        "GroupSet": [
          {
            "Ref": "jenkinsSg"
          },
          {
            "Ref": "usersSshSg"
          }
        ]
      }
    ],
    "UserData": {
      "Fn::Base64": {
        "Fn::Join": [
          "",
          [
            "#!/bin/bash -v\n",
            "# Run Jenkins docker image\n",
            "cd /home/ec2-user/price_aws/images/jenkins\n",
            "docker-compose up &\n"
          ]
        ]
      }
    }
  }
}

}

据我所知,一旦实例运行,就应该执行UserData。

我做错了什么?

问候。

0 个答案:

没有答案