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
posta 8 mesi fa632 visualizzazioni
1 Risposta
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
con risposta 8 mesi fa
profile picture
ESPERTO
verificato 2 mesi fa

Accesso non effettuato. Accedi per postare una risposta.

Una buona risposta soddisfa chiaramente la domanda, fornisce un feedback costruttivo e incoraggia la crescita professionale del richiedente.

Linee guida per rispondere alle domande