Docker on Amazon Web Services
上QQ阅读APP看书,第一时间看更新

Creating an ECS task definition

Now that you have set up your ECS cluster and understand how ECS container instances register with the cluster, it's time to configure an ECS task definition, which defines the configuration of the containers you want to deploy for your application. ECS task definitions can define one or more containers, along with other elements, such as volumes, that your containers may need to read or write to.

To keep things simple, we are going to create a very basic task definition that will run the official Nginx Docker image, which is published at https://hub.docker.com/_/nginx/. Nginx is a popular web server, which by default will serve a Welcome to Nginx page, and for now this will suffice to represent a simple web application.

Let's now create an ECS task definition for our simple web application by performing the following steps:

  1. Navigate to the ECS console at Services | Elastic Container Service. You can create a new task definition by selecting Task Definitions from the left-hand menu and clicking the Create new Task Definition button.
  2. In the Select launch type compatibility screen, select the EC2 launch type, which will configure the task definition to be launched on ECS clusters based upon the infrastructure that you own and manage.
  3. In the Configure task and container definitions screen, configure a Task Definition Name of simple-web and then scroll down and click Add container to add a new container definition.
  4. In the Add container screen, configure the following settings and once complete click the Add button to create the container definition. This container definition will map port 80 on ECS container hosts to port 80 in the container, allowing access to the Nginx web server from the outside world:
    • Container name: nginx
    • Image: nginx
    • Memory Limits: 250 MB Hard limit
    • Port mappings: Host port 80, Container port 80, Protocol tcp:
Creating a Container Definition
  1. Complete creation of the task definition by clicking the Create button at the bottom of the Configure task and container definitions page.