如何正确配置Lightsail容器之间的通信

0

【以下的问题经过翻译处理】 我想要部署两个容器,一个是"nginx",另一个是"php-fpm(Laravel)"。

本地使用docker-compose创建是可以正常使用的。但是在Lightsail中失败了。 Lightsail日志说找不到名为php-fpm的容器,而我在container.yml中设置了它的名称。

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

第24行是fastcgi_pass php:9000;,表示找不到php容器的名称。 我认为设置方法与docker-compose一样,可以通过指定容器名称来使每个容器之间通信。

因此,我的问题是,如何正确配置两个容器之间通信。

这是设置。

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

profile picture
专家
已提问 2 年前64 查看次数
1 回答
0

【以下的回答经过翻译处理】 Lightsail容器不包含docker-compose的DNS。您需要告诉Lightsail端口并在内部进行暴露。 更改nginx.conf fastcgi_pass php:9000; -> fastcgi_pass localhost:9000; 在container.yml中添加:

php:
   "ports": {
     "9000": "HTTP"
   }
profile picture
专家
已回答 2 年前

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

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

回答问题的准则