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달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠