Communication Between Lightsail Containers

2

I want to deploy two containers which is "nginx" and "php-fpm(Laravel)".

I already create and make it work on local using docker-compose. But by Lightsail it failed. Lightsail logs said php-fpm container not found which I set the name on container.yml.

nginx: [emerg] host not found in upstream "php" in /etc/nginx/conf.d/default.conf:24

The line 24 isfastcgi_pass php:9000;, indicating the name of php container not found. Like docker-compose, I thought it would be possible with specifying container name can communicate between each containers.

So, my question is what is the right way to configure for communicate between two container.

Here is the settings.

nginx default.conf

server {
  listen 80 default_server;
  listen [::]:80 default_server;

  server_name _;

  root /app/public;

  add_header X-Frame-Options "SAMEORIGIN";
  add_header X-XSS-Protection "1; mode=block";
  add_header X-Content-Type-Options "nosniff";

  index index.html index.htm index.php;

  charset utf-8;

  location / {
      try_files $uri $uri/ /index.php?$args;
  }

  location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    include fastcgi_params;
    fastcgi_buffer_size 32k;
    fastcgi_buffers 4 32k;
    fastcgi_read_timeout 1200s;
    fastcgi_send_timeout 1200s;
  }
}

Lightsail container.yml

serviceName: ${SERVICE_NAME}
containers:
    nginx:
        command: []
        image: ${LATEST_NGINX_LIGHTSAIL_DOCKER_IMAGE}
        ports:
            '80': HTTP
    php:
        command: []
        image: ${LATEST_PHP_LIGHTSAIL_DOCKER_IMAGE}
publicEndpoint:
    containerName: nginx
    containerPort: 80
    healthCheck:
        healthyThreshold: 2
        intervalSeconds: 20
        path: /api/healthcheck
        successCodes: 200-499
        timeoutSeconds: 4
        unhealthyThreshold: 2
질문됨 2년 전1634회 조회
2개 답변
2
수락된 답변

Lightsail containers don't contain the DNS magic that docker-compose has. You'll need to tell Lightsail about the port and expose it internally.

Change nginx.conf fastcgi_pass php:9000; -> fastcgi_pass localhost:9000;

Add to container.yml

php:
   "ports": {
     "9000": "HTTP"
   }
답변함 2년 전
AWS
전문가
검토됨 2년 전
1

thank you for the answer @mreferre

For the sake of completeness, i would like to refer to the section in the lightsail documentation i just became aware of: https://lightsail.aws.amazon.com/ls/docs/en_us/articles/amazon-lightsail-container-services -> "Private domain"

To access a specific container using the private domain of your container service, you must specify the open port of the container that will accept your connection request. You do this by formatting the domain of your request as <ServiceName>.service.local:<PortNumber>, in which <ServiceName> is the name of your container service and <PortNumber> is the open port of the container that you wish to connect to. For example, if you create a deployment on your container service named container-service-1, and you specify a Redis container with port 6379 open, then you should format the domain of your request as container-service-1.service.local:6379.

Sandro
답변함 2년 전

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

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

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