docker-compose 在 nodejs 和 yarn 上构建时出错:

docker-compose 在 nodejs 和 yarn 上构建时出错:

我一直在尝试让一个项目为我的工作服务。我最近买了一台 M1 Air,但是当我在装有 WSL 的 Windows 机器上做同样的事情时,也遇到了类似的问题。错误如下:

    #8 8.455 ## To install the Yarn package manager, run:
#8 8.455      curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
#8 8.455      echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
#8 8.455      sudo apt-get update && sudo apt-get install yarn
#8 8.455
#8 8.455
#8 8.455 + apt-get install -y nodejs
#8 8.462 Reading package lists...
#8 8.805 Building dependency tree...
#8 8.871 Reading state information...
#8 8.942 The following NEW packages will be installed:
#8 8.942   nodejs
#8 9.093 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
#8 9.093 Need to get 24.5 MB of archives.
#8 9.093 After this operation, 121 MB of additional disk space will be used.
#8 9.093 Get:1 https://deb.nodesource.com/node_14.x buster/main arm64 nodejs arm64 14.18.2-deb-1nodesource1 [24.5 MB]
#8 12.29 debconf: delaying package configuration, since apt-utils is not installed
#8 12.30 Fetched 24.5 MB in 3s (7,533 kB/s)
#8 12.32 Selecting previously unselected package nodejs.
(Reading database ... 23271 files and directories currently installed.)
#8 12.33 Preparing to unpack .../nodejs_14.18.2-deb-1nodesource1_arm64.deb ...
#8 12.33 Unpacking nodejs (14.18.2-deb-1nodesource1) ...
#8 13.92 Setting up nodejs (14.18.2-deb-1nodesource1) ...
#8 13.94 + curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg
#8 13.94 + apt-key add -
#8 13.97 Warning: apt-key output should not be parsed (stdout is not a terminal)
#8 14.39 gpg: no valid OpenPGP data found.
------
executor failed running [/bin/bash -oeux pipefail -c curl -sL https://deb.nodesource.com/setup_14.x | bash -  &&   apt-get install -y nodejs &&   curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - &&   echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&   apt-get update && apt-get install yarn]: exit code: 2
ERROR: Service 'app' failed to build : Build failed

有人经历过类似的事情吗?这是我的dockerfile。

FROM php:7.4-fpm-buster
SHELL ["/bin/bash", "-oeux", "pipefail", "-c"]

# timezone environment
ENV TZ=UTC \
  # locale
  LANG=en_US.UTF-8 \
  LANGUAGE=en_US:en \
  LC_ALL=en_US.UTF-8 \
  # composer environment
  COMPOSER_ALLOW_SUPERUSER=1 \
  COMPOSER_HOME=/composer \
  # Laravel environment
  APP_SERVICES_CACHE=/tmp/cache/services.php \
  APP_PACKAGES_CACHE=/tmp/cache/packages.php \
  APP_CONFIG_CACHE=/tmp/cache/config.php \
  APP_ROUTES_CACHE=/tmp/cache/routes.php \
  APP_EVENTS_CACHE=/tmp/cache/events.php \
  VIEW_COMPILED_PATH=/tmp/cache/views

COPY --from=composer:1.10 /usr/bin/composer /usr/bin/composer

RUN apt-get update && \
  apt-get -y install git libicu-dev libonig-dev libzip-dev unzip locales libpq-dev libpng-dev libjpeg-dev libfreetype6-dev imagemagick libmagickwand-dev && \
  pecl install imagick && \
  docker-php-ext-enable imagick && \
  docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/ && \
  docker-php-ext-install -j$(nproc) gd pdo pdo_pgsql && \
  apt-get clean && \
  rm -rf /var/lib/apt/lists/* && \
  locale-gen en_US.UTF-8 && \
  localedef -f UTF-8 -i en_US en_US.UTF-8 && \
  mkdir /var/run/php-fpm && \
  mkdir -p /tmp/cache/views && \
  chmod 777 -R /tmp/cache && \
  docker-php-ext-install intl pdo_mysql zip bcmath && \
  composer config -g process-timeout 3600 && \
  composer config -g repos.packagist composer https://packagist.org && \
  composer global require hirak/prestissimo

# node and yarn
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash -  && \
  apt-get install -y nodejs && \
  curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
  echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
  apt-get update && apt-get install yarn

RUN yarn global add secure-spreadsheet

COPY ./php-fpm.d/backend-www.conf /usr/local/etc/php-fpm.d/zzz-www.conf
COPY ./php.ini /usr/local/etc/php/php.ini

WORKDIR /work/backend

我尝试了一个解决方案谷歌搜索但最终却得到了另一个错误:

failed to solve with frontend dockerfile.v0: failed to create LLB definition: dockerfile parse error line 41: unknown instruction: APT-GET ERROR: Service 'app' failed to build : Build failed

我也发帖寻求帮助Reddit不久前,我希望能够更快地得到问题的答案。任何帮助都将不胜感激!

答案1

解决方案:问题在于无法读取 yarn 包的公钥,因此解决方案是添加此行。

RUN cat pubkey.gpg | apt-key add -

感谢 VictorXLRgithub

相关内容