Docker 图片在 AWS Fargate 上不工作,但在 EC2 上工作

Docker image does not work on AWS Fargate but it does in EC2

我正在更改 AWS 上的基础设施,我想将 Docker (ECS) 与 Fargate 一起使用。我的 Docker 图像是基于 Ubuntu 的,我在里面安装了我需要的所有东西。我在 NGINX 运行ning PHP 7.2 上使用 Laravel 5.6。我的 Docker 容器在我的本地机器上运行,如果我使用 EC2 运行 ECS,但是当我更改为 Fargate 时它 returns NGINX 500 错误。我做了一些测试,我知道 PHP 是 运行ning,只有当我安装我的 Laravel 应用程序时才会发生错误。

因为我无法访问 Fargate 机器,所以我不知道如何调试。我尝试将 NGINX 与 Loggly 连接,但它需要 rsyslog,并且由于我使用的是 Docker,它无法访问 Ubuntu 的核心。当我安装并尝试 运行 时 returns:

rsyslogd: imklog: cannot open kernel log (/proc/kmsg): Operation not permitted

这是我的Docker文件:

FROM ubuntu:latest

ENV BACKEND_PATH=/code/Backend
ENV FRONTEND_PATH=/code/Frontend

## Update
RUN apt-get update -y

## Upgrade
RUN apt-get install -y software-properties-common
RUN add-apt-repository -y ppa:certbot/certbot
RUN apt-get update -y
RUN apt-get upgrade -y
RUN apt-get dist-upgrade -y
RUN apt-get autoremove -y
RUN apt-get update -y

## Nano
RUN apt-get install -y nano

## Timezone
RUN echo "America/Sao_Paulo" > /etc/timezone && \
    apt-get install -y tzdata && \
    rm /etc/localtime && \
    ln -snf /usr/share/zoneinfo/America/Sao_Paulo /etc/localtime && \
    dpkg-reconfigure -f noninteractive tzdata && \
    apt-get clean

## Git
RUN apt-get install -y git

## NGINX
RUN apt-get install -y nginx
COPY ./nginx/app/sites-available /etc/nginx/sites-available
COPY ./nginx/app/sites-available /etc/nginx/sites-enabled
COPY ./nginx/sites /etc/nginx/sites
COPY ./nginx/ssl /ssl

## PHP
RUN apt-get install -y php-cli php-fpm php-curl php-mbstring
COPY ./php/php.ini /usr/local/etc/php

# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

# Install libs
RUN apt-get install -y php-zip php-mysql php-gd pngquant gifsicle jpegoptim libicu-dev g++ php-intl php-xml

## Crontab
RUN apt-get install -y cron
COPY crontab newcrontab
RUN crontab newcrontab
RUN rm newcrontab

## Supervisor
RUN apt-get install -y supervisor
COPY ./supervisord /etc/supervisor/conf.d

## Certbot
RUN apt-get install -y python-certbot-nginx

## Install apps
COPY ./code/Backend /code/Backend
COPY ./code/Frontend/dist /code/Frontend/dist

RUN cd ${BACKEND_PATH} && chmod +x composer.phar && ./composer.phar self-update && php composer.phar install
RUN chmod -Rf 777 ${BACKEND_PATH}/storage
RUN chmod -Rf 777 ${BACKEND_PATH}/resources
RUN php ${BACKEND_PATH}/artisan config:clear
RUN php ${BACKEND_PATH}/artisan passport:keys

## Run!
EXPOSE 80 443

RUN service php7.2-fpm start
CMD ["/usr/bin/supervisord"]

我认为这个错误与权限有关,但如果没有错误消息,几乎不可能知道发生了什么......有人知道我如何找到这个吗?

在 ServerFault 上查看这个答案:https://serverfault.com/questions/691048/kernel-log-stays-empty-rsyslogd-imklog-cannot-open-kernel-log-proc-kmsg

使用 --privileged 标志尝试 运行 Fargate 任务。您可以在任务定义中的每个容器的 AWS 控制台中设置此标志。它位于容器定义末尾附近的 SECURITY 部分。 Here's the full reference for container definitions.

我想通了。实际上真是愚蠢的错误。当我创建 Fargate 配置时,我使用了一个没有权限访问某些 AWS 组件的安全组,因此应用程序无法启动。