forked from aliyun/ros-templates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ecs-docker.yml
114 lines (114 loc) · 3.17 KB
/
ecs-docker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
ROSTemplateFormatVersion: '2015-09-01'
Description:
en: Deploy Docker on the Alibaba Cloud ECS based on the CentOS 7.9 operating system
and make a Docker image.
zh-cn: 在阿里云云服务器ECS上基于CentOS 7.9操作系统部署Docker,并制作Docker镜像。
Parameters:
InstanceId:
Type: String
Label:
en: ECS Instance ID
zh-cn: ECS实例ID
Description:
en: Please select a test ECS instance whose operating system is CentOS 7.9.
zh-cn: 请选择操作系统为CentOS 7.9的测试ECS实例。
AssociationProperty: ALIYUN::ECS::Instance::InstanceId
Resources:
DS_Instances:
Type: DATASOURCE::ECS::Instances
Properties:
InstanceIds:
- Ref: InstanceId
SecurityGroupIngress_22:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 22/22
SecurityGroupIngress_80:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 80/80
SecurityGroupIngress_8080:
Type: ALIYUN::ECS::SecurityGroupIngress
Properties:
SecurityGroupId:
Fn::Jq:
- First
- .[0].SecurityGroupIds[0]
- Fn::GetAtt:
- DS_Instances
- Instances
SourceCidrIp: 0.0.0.0/0
IpProtocol: tcp
NicType: intranet
PortRange: 8080/8080
InstallDocker:
Type: ALIYUN::ECS::RunCommand
Properties:
InstanceIds:
- Ref: InstanceId
Type: RunShellScript
Sync: true
Timeout: 3600
CommandContent:
Fn::Sub: |-
#!/bin/bash
wget -O /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum -y install docker-ce
systemctl start docker
systemctl enable docker
docker pull nginx:1.23.4
touch Dockerfile
cat > Dockerfile << EOF
FROM nginx:1.23.4
RUN echo '<h1>Welcome, Docker!</h1>' > /usr/share/nginx/html/index.html
EOF
docker build -t image001:v1 .
docker rm -f nginx-test
docker run --name nginx-test -p 8080:80 -d image001:v1
DependsOn:
- SecurityGroupIngress_22
- SecurityGroupIngress_80
- SecurityGroupIngress_8080
Outputs:
DockerUrl:
Description:
en: Docker page.
zh-cn: Docker页面。
Value:
Fn::Sub:
- http://${IP}:8080
- IP:
Fn::Jq:
- First
- if .[0].PublicIpAddress != [] then .[0].PublicIpAddress[0] else .[0].EipAddress.IpAddress
end
- Fn::GetAtt:
- DS_Instances
- Instances
Metadata:
ALIYUN::ROS::Interface:
ParameterGroups:
- Parameters:
- InstanceId
TemplateTags:
- acs:document:试用教程:在ECS上部署并使用Docker