简体   繁体   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

I'm new with docker, and i try to "dockerise" an existing symfony project.我是 docker 新手,我尝试“dockerise”一个现有的 symfony 项目。 To begin this i've created only a Dockerfile in my symfony project that i frequently test using docker build .首先,我在我的 symfony 项目中只创建了一个 Dockerfile,我经常使用 docker docker build . command.命令。 until the part of my dockerfile where直到我的 dockerfile 的一部分在哪里

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

the command docker build .命令docker build . works well.效果很好。 But when i reach this part i obtain this error :但是当我到达这部分时,我得到了这个错误:

=> 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

I don't know if it is usefull to share all the error but i've did it if it is.我不知道分享所有错误是否有用,但如果是的话,我已经做到了。

And here is my code in my Dockerfile :这是我在 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/

I don't know how to solve this error in order to my npm packages can be uploaded in my docker stack.我不知道如何解决这个错误,以便我的 npm 包可以上传到我的 docker 堆栈中。 I'm sorry if this question seems to be stupid but i'm not familiar with docker.如果这个问题看起来很愚蠢,我很抱歉,但我不熟悉 docker。 Thanks in advance to anyone who takes the time to answer my question.提前感谢任何花时间回答我问题的人。

edit : after replaced npm run build by npm run watch what corresponding to the content of package.json in script the new log is :编辑:用 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 says " npm ERR! missing script: build " its looks loke you have no instructions for " build " when do " npm run build " try to check your package.json file, it may looks like this: NPM 说“ npm ERR! missing script: build ”看起来你没有关于“ build ”的说明,当“ npm run build ”尝试检查你的 package.json 文件时,它可能看起来像这样:

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

To run跑步

npm run build

You must have a package.json file with a您必须有一个 package.json 文件,其中包含

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

instruction in it.里面的指令。

Do you have the package.json file in your project?你的项目中有 package.json 文件吗? Does it have the "build" script in it?它里面有“构建”脚本吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM