簡體   English   中英

=> 錯誤 [8/9] 在 dockerfile symfony php 項目中運行 cd /var/www && composer install && npm install && npm run build

[英]=> ERROR [8/9] RUN cd /var/www && composer install && npm install && npm run build in a dockerfile symfony php project

我是 docker 新手,我嘗試“dockerise”一個現有的 symfony 項目。 首先,我在我的 symfony 項目中只創建了一個 Dockerfile,我經常使用 docker docker build . 命令。 直到我的 dockerfile 的一部分在哪里

RUN cd /var/www && \
    composer install && \
    npm install && \
    npm run build

命令docker build . 效果很好。 但是當我到達這部分時,我得到了這個錯誤:

=> ERROR [8/9] RUN cd /var/www &&     composer install &&     npm install &&     npm run build                                                                                    8.9s
------
 > [8/9] RUN cd /var/www &&     composer install &&     npm install &&     npm run build:
#14 0.419 Do not run Composer as root/super user! See https://getcomposer.org/root for details
#14 0.462 Installing dependencies from lock file (including require-dev)
#14 0.462 Verifying lock file contents can be installed on current platform.
#14 0.469 Package operations: 3 installs, 0 updates, 0 removals
#14 0.470     Failed to download symfony/polyfill-mbstring from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 0.470 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 0.470     Now trying to download from source
#14 0.472   - Syncing symfony/polyfill-mbstring (v1.26.0) into cache
#14 1.791     Failed to download symfony/polyfill-ctype from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 1.791 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 1.791     Now trying to download from source
#14 1.791   - Syncing symfony/polyfill-ctype (v1.26.0) into cache
#14 2.467     Failed to download twig/twig from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 2.467 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 2.467     Now trying to download from source
#14 2.467   - Syncing twig/twig (v3.4.1) into cache
#14 4.683     0 [>---------------------------]    0 [->--------------------------]
#14 4.684   - Installing symfony/polyfill-mbstring (v1.26.0): Cloning 9344f9cb97 from cache
#14 4.730   - Installing symfony/polyfill-ctype (v1.26.0): Cloning 6fd1b9a79f from cache
#14 4.774   - Installing twig/twig (v3.4.1): Cloning e939eae923 from cache
#14 5.154     0 [>---------------------------]    0 [->--------------------------]
#14 5.277 Generating autoload files
#14 5.278 3 packages you are using are looking for funding.
#14 5.278 Use the `composer fund` command to find out more!
#14 8.457
#14 8.457 up to date, audited 191 packages in 3s
#14 8.469
#14 8.469 13 vulnerabilities (2 moderate, 8 high, 3 critical)
#14 8.469
#14 8.469 To address issues that do not require attention, run:
#14 8.469   npm audit fix
#14 8.469
#14 8.469 To address all issues (including breaking changes), run:
#14 8.469   npm audit fix --force
#14 8.469
#14 8.469 Run `npm audit` for details.
#14 8.812 npm ERR! missing script: build
#14 8.828
#14 8.828 npm ERR! A complete log of this run can be found in:
#14 8.828 npm ERR!     /root/.npm/_logs/2022-06-13T20_28_53_643Z-debug.log
------
executor failed running [/bin/sh -c cd /var/www &&     composer install &&     npm install &&     npm run build]: exit code: 1

我不知道分享所有錯誤是否有用,但如果是的話,我已經做到了。

這是我在 Dockerfile 中的代碼:

FROM php:8.1-apache

ADD https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/

RUN chmod +x /usr/local/bin/install-php-extensions && \
    install-php-extensions pdo_mysql

RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
   mv composer.phar /usr/local/bin/composer

# install nodejs

RUN apt-get update && apt-get upgrade -y && \
    apt-get install -y nodejs \
    npm

COPY . /var/www/

COPY ./docker/apache.conf /etc/apache2/sites-available/000-default.conf

RUN cd /var/www && \
    composer install && \
    npm install && \
    npm run build

WORKDIR /var/www/

我不知道如何解決這個錯誤,以便我的 npm 包可以上傳到我的 docker 堆棧中。 如果這個問題看起來很愚蠢,我很抱歉,但我不熟悉 docker。 提前感謝任何花時間回答我問題的人。

編輯:用 npm run 替換npm run build后, npm run watch script中 package.json 的內容對應的新日志是:

=> ERROR [8/9] RUN cd /var/www &&     composer install &&     npm install &&     npm run watch                                                                                   11.7s
------
 > [8/9] RUN cd /var/www &&     composer install &&     npm install &&     npm run watch:
#14 0.871 Do not run Composer as root/super user! See https://getcomposer.org/root for details
#14 0.957 Installing dependencies from lock file (including require-dev)
#14 0.958 Verifying lock file contents can be installed on current platform.
#14 0.974 Package operations: 3 installs, 0 updates, 0 removals
#14 0.975     Failed to download symfony/polyfill-mbstring from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 0.975 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 0.975     Now trying to download from source
#14 0.980   - Syncing symfony/polyfill-mbstring (v1.26.0) into cache
#14 1.768     Failed to download symfony/polyfill-ctype from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 1.768 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 1.768     Now trying to download from source
#14 1.768   - Syncing symfony/polyfill-ctype (v1.26.0) into cache
#14 2.482     Failed to download twig/twig from dist: The zip extension and unzip/7z commands are both missing, skipping.
#14 2.482 Your command-line PHP is using multiple ini files. Run `php --ini` to show them.
#14 2.482     Now trying to download from source
#14 2.482   - Syncing twig/twig (v3.4.1) into cache
#14 5.854     0 [>---------------------------]    0 [->--------------------------]
#14 5.858   - Installing symfony/polyfill-mbstring (v1.26.0): Cloning 9344f9cb97 from cache
#14 5.962   - Installing symfony/polyfill-ctype (v1.26.0): Cloning 6fd1b9a79f from cache
#14 6.040   - Installing twig/twig (v3.4.1): Cloning e939eae923 from cache
#14 6.878     0 [>---------------------------]    0 [->--------------------------]
#14 7.167 Generating autoload files
#14 7.174 3 packages you are using are looking for funding.
#14 7.174 Use the `composer fund` command to find out more!
#14 10.95
#14 10.95 up to date, audited 191 packages in 3s
#14 10.98
#14 10.98 13 vulnerabilities (2 moderate, 8 high, 3 critical)
#14 10.98
#14 10.98 To address issues that do not require attention, run:
#14 10.98   npm audit fix
#14 10.98
#14 10.98 To address all issues (including breaking changes), run:
#14 10.98   npm audit fix --force
#14 10.98
#14 10.98 Run `npm audit` for details.
#14 11.51
#14 11.51 > grenier-en-ligne@1.0.0 watch
#14 11.51 > node-sass -w style -o public/style
#14 11.51
#14 11.52 /var/www/node_modules/.bin/node-sass: 1: ../node-sass/bin/node-sass: not found
#14 11.53 npm ERR! code 127
#14 11.53 npm ERR! path /var/www
#14 11.53 npm ERR! command failed
#14 11.53 npm ERR! command sh -c node-sass -w style -o public/style
#14 11.56
#14 11.56 npm ERR! A complete log of this run can be found in:
#14 11.56 npm ERR!     /root/.npm/_logs/2022-06-13T21_10_42_941Z-debug.log
------
executor failed running [/bin/sh -c cd /var/www &&     composer install &&     npm install &&     npm run watch]: exit code: 127

NPM 說“ npm ERR! missing script: build ”看起來你沒有關於“ build ”的說明,當“ npm run build ”嘗試檢查你的 package.json 文件時,它可能看起來像這樣:

"scripts": {
    "dev": "...",
    "build": "...",
    "test": "..."
  },

跑步

npm run build

您必須有一個 package.json 文件,其中包含

  "scripts": {
     "build": "...",
  }

里面的指令。

你的項目中有 package.json 文件嗎? 它里面有“構建”腳本嗎?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM