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
已提問 8 個月前檢視次數 632 次
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
已回答 8 個月前
profile picture
專家
已審閱 2 個月前

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南