首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >码头拉<image>在云格式UserData标签中不工作

码头拉<image>在云格式UserData标签中不工作
EN

Stack Overflow用户
提问于 2021-11-29 20:01:45
回答 1查看 213关注 0票数 1
代码语言:javascript
复制
UserData:
  'Fn::Base64': |
    #!/bin/bash
    yum -y install docker
    dockerd
    docker pull apache/superset

在上面提到的Cloudformation标记中:一切都在工作,直到dockerd。码头拉命令不执行。模板不会产生任何错误。但是,当我将ssh放到由cloudformation模板创建的ec2实例中时,我没有看到停靠者图像。我能够在docker pull <image>上手动运行ec2,它可以工作。

是否需要任何特定的设置来从ec2上的对接中心(而不是ECR)从云形成模板中提取图像?

我的整个CF模板供参考:

代码语言:javascript
复制
Parameters:
  InstanceType:
    Type: String
    Default: t2.micro
    Description: Enter instance size. Default is t3a.medium.
    AllowedValues: # dropdown options
      - t1.nano
      - t1.micro
      - t2.micro
  Key:
    Type: AWS::EC2::KeyPair::KeyName
    Default: aseem-ec2-eu-west-1
    Description: The key used to access the instance.

Mappings:
  AmiIdForRegion:
    us-east-1:
      AMI: ami-04ad2567c9e3d7893
    eu-west-1:
      AMI: ami-09d4a659cdd8677be

Resources:
  VPC:
    Type: AWS::EC2::VPC
    Properties:
      CidrBlock: 172.34.0.0/16
      EnableDnsSupport: true
      EnableDnsHostnames: true
      InstanceTenancy: default
      Tags:
        - Key: Name
          Value: Linux VPC
  InternetGateway:
    Type: AWS::EC2::InternetGateway
  VPCGatewayAttachment:
    Type: AWS::EC2::VPCGatewayAttachment
    Properties:
      VpcId: !Ref VPC
      InternetGatewayId: !Ref InternetGateway
  SubnetA:
    Type: AWS::EC2::Subnet
    Properties:
      AvailabilityZone: eu-west-1a
      VpcId: !Ref VPC
      CidrBlock: 172.34.1.0/24
      MapPublicIpOnLaunch: true
  RouteTable:
    Type: AWS::EC2::RouteTable
    Properties:
      VpcId: !Ref VPC
  InternetRoute:
    Type: AWS::EC2::Route
    DependsOn:
      - InternetGateway
      - VPCGatewayAttachment
    Properties:
      DestinationCidrBlock: 0.0.0.0/0
      GatewayId: !Ref InternetGateway
      RouteTableId: !Ref RouteTable

  SubnetARouteTableAssociation:
    Type: AWS::EC2::SubnetRouteTableAssociation
    Properties:
      RouteTableId: !Ref RouteTable
      SubnetId: !Ref SubnetA

  SecurityGroup:
    Type: 'AWS::EC2::SecurityGroup'
    Properties:
      GroupDescription: Enable HTTP access via port 80
      GroupName: superset-ec2-security-group-3
      VpcId: !Ref VPC
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 8080 # HTTP- port 80
          ToPort: 8080
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 22 # ssh
          ToPort: 22
          CidrIp: 0.0.0.0/0
        - IpProtocol: tcp
          FromPort: 443
          ToPort: 443
          CidrIp: 0.0.0.0/0
      SecurityGroupEgress: # all external traffic
        - IpProtocol: -1
          CidrIp: 0.0.0.0/0
  ElasticIP:
    Type: AWS::EC2::EIP
    Properties:
      Domain: vpc
      InstanceId: !Ref LinuxEc2

  LinuxEc2:
    Type: AWS::EC2::Instance
    Properties:
      SubnetId: !Ref SubnetA
      SecurityGroupIds:
        - !Ref SecurityGroup
      ImageId: !FindInMap [ AmiIdForRegion,!Ref AWS::Region,AMI ]
      KeyName: !Ref Key
      InstanceType: !Ref InstanceType
      BlockDeviceMappings:
        - DeviceName: /dev/xvda
          Ebs:
            VolumeSize: 100
      Tags:
        - Key: Name # naming your instance
          Value: superset-6
      UserData:
        'Fn::Base64': |
          #!/bin/bash
          yum -y install docker
          dockerd
          docker pull apache/superset


Outputs:
  PublicDnsName:
    Value: !GetAtt LinuxEc2.PublicDnsName
  PublicIp:
    Value: !GetAtt LinuxEc2.PublicIp
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-30 01:27:41

不应该在用户数据中执行 dockerd。这将启动docker守护进程并冻结进一步的执行。相反,它应该是:

代码语言:javascript
复制
      UserData:
        'Fn::Base64': |
          #!/bin/bash
          yum -y install docker
          systemctl enable docker
          systemctl start docker
          docker pull apache/superset
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70160658

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档