userdata
=
"""
#!/bin/bash
echo ECS_CLUSTER=cookbook >> /etc/ecs/ecs.config
"""
c
=
boto
.
connect_ec2
()
c
.
run_instances
(
'ami-34ddbe5c'
,
\
key_name
=
'ecs'
,
\
instance_type
=
't2.micro'
,
\
instance_profile_name
=
'cookbook'
,
\
user_data
=
base64
.
b64encode
(
userdata
))
Once you are done with the cluster, you can
delete it entirely with the
aws ecs
delete-cluster --cluster cookbook
command.
See Also
• The
ECS
agent
on GitHub
8.13 Starting Docker Containers on an ECS Cluster
Problem
You know how to create an ECS cluster on AWS (see
Recipe 8.12
), and now you are
ready to start containers on the instances forming the cluster.
Solution
Define your containers or group of containers in a definition file in JSON format.
This
will be called a
task
. You will register this task and then run it;
it is a two-step
process. Once the task is running in the cluster, you can
list
,
stop
, and
start
it.
For example, to run Nginx
in a container based on the
nginx
image from Docker
Hub, you create the following task definition in JSON format:
[
{
"environment"
:
[],
"name"
:
"nginx"
,
"image"
:
"nginx"
,
"cpu"
:
10
,
Do'stlaringiz bilan baham: