ecs multi-container

0

I need to know how the multi-container can be flashed inside the task defination like, nginx on 80 port jenkins on 8080 elastic search on 9200 kibana on 5601 if ec2 is used within the cluster then how can i do.

nitin
已提问 7 个月前574 查看次数
1 回答
0

Hi, you can define multiple container definitions in your task definition. For example. the following task definition (in YAML) has an Apache HTTP Server container on port 80 and a Node.js Application Server container on port 3000.

Resources:
  TaskDefinition:
    Type: AWS::ECS::TaskDefinition
    Properties:
      Family:
        Fn::Sub: ${AWS::StackName}-TaskDefinition
      Cpu: 256
      Memory: 512
      NetworkMode: awsvpc
      RequiresCompatibilities:
        - FARGATE
      RuntimePlatform:
        OperatingSystemFamily: LINUX
      ExecutionRoleArn:
        Fn::GetAtt: ECSExecutionRole.Arn
      TaskRoleArn:
        Fn::GetAtt: ECSTaskRole.Arn
      ContainerDefinitions:
        - Name: httpd
          Image: httpd:latest
          Command:
            - /bin/sh
            - -c
            - |
              cat <<EOF > /usr/local/apache2/htdocs/index.html
              <h1>It works!</h1>
              <p>Your container hostname is `hostname`.</p>
              EOF

              sed -i \
                  -e 's/^#\(LoadModule .*mod_proxy_http.so\)/\1/' \
                  -e 's/^#\(LoadModule .*mod_proxy.so\)/\1/' \
                  conf/httpd.conf

              cat <<\EOF >> conf/httpd.conf
              <IfModule proxy_module>
              Include conf/extra/proxy.conf
              </IfModule>
              EOF

              cat <<\EOF >> conf/extra/proxy.conf
              ProxyPass "/proxy" "http://localhost:3000/"
              ProxyPassReverse "/proxy" "http://localhost:3000/"
              EOF

              apt update -y && apt install -y curl
              httpd-foreground
          Essential: true
          PortMappings:
            - ContainerPort: 80
              HostPort: 80
              Protocol: tcp
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-region:
                Ref: AWS::Region
              awslogs-group:
                Ref: ECSLogGroup
              awslogs-stream-prefix: httpd
          HealthCheck:
            Command:
              - CMD-SHELL
              - curl -f http://localhost || exit 1
            StartPeriod: 30
        - Name: node
          Image: node:latest
          Command:
            - /bin/sh
            - -c
            - |
              cat <<\EOF > main.js
              const http = require("http");

              const hostname = "0.0.0.0";
              const port = 3000;

              const server = http.createServer((req, res) => {
                res.statusCode = 200;
                res.setHeader("Content-Type", "text/html");
                res.end("<h1>Hello World!</h1>\n");
              });

              server.listen(port, hostname, () => {
                console.log(`Server running at http://${hostname}:${port}/`);
              });
              EOF

              node main.js
          LogConfiguration:
            LogDriver: awslogs
            Options:
              awslogs-region:
                Ref: AWS::Region
              awslogs-group:
                Ref: ECSLogGroup
              awslogs-stream-prefix: node
          HealthCheck:
            Command:
              - CMD-SHELL
              - curl -f http://localhost:3000 || exit 1
            StartPeriod: 30

For detailed reference about task definition, read the following documentations.

profile picture
HS
已回答 7 个月前
profile picture
专家
已审核 1 个月前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则