【问题标题】:DOCKER: error when running gulp-php websiteDOCKER:运行 gulp-php 网站时出错
【发布时间】:2020-07-06 20:47:51
【问题描述】:

我正在尝试使用 Docker 来运行我的 php - gulp 网站。 这是我创建的树:

├── app <--------------------contains the php files
├── blog-theme
├── bower_components
├── changelog-YYYY-MM-DD.md
├── dist
├── Dockerfile <-----------------------DOCKERFILE
├── get-git-log.sh
├── git-log.txt
├── gulpfile.js <------------------all my gulp tasks are here 
├── node_modules
├── package.json
├── package-lock.json
├── README.md
├── Releases
├── ressources
├── website_test.sh
└── yarn.lock

app 文件夹包含我所有的 php 文件:

app
├── folder1
│   └── index.php
├── folder2
│   └── index.php
├── folder3
│   └── index.php
├── footer.php
├── header.php
└── index.php

我的 gulpfile.js 包含编译和构建我的网站的所有任务。它运作良好。由于我创建的任务的名称,我用来运行的命令是 gulp build-production &amp;&amp; gulp serve:dist

所以在我的 Dockerfile 中,我添加了以下几行以使我的应用程序在我的 Docker 中运行:

FROM ubuntu:16.04

WORKDIR /app

RUN apt-get update
RUN apt-get install -y build-essential
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get install -y nodejs
RUN npm install -g npm
RUN npm install -g n
RUN n 13.6.0
RUN npm i gulp@4.0.2
RUN npm i gulp-cli

VOLUME ["/app"]
CMD ["gulp build-production && gulp serve:dist"]

当我运行 docker build -t myapp . 时,所有步骤都运行良好,没有返回任何错误。

但是当我运行docker run myapp 时,出现以下错误:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:349: starting container process caused "exec: \"gulp build-production && gulp serve:dist\": executable file not found in $PATH": unknown.
ERRO[0001] error waiting for container: context canceled 

我很困惑,所以如果有人有解决方案,那就太棒了。

【问题讨论】:

  • 删除CMD 行周围的括号和引号。我还建议删除 VOLUME 行,更直接地安装 Node(甚至可能只使用 Ubuntu nodejs 包)。
  • 大卫给出了很好的建议,对不起,这不是问题的一部分,但为了遵循良好的做法而思考。您可以通过将多个命令合并为一个 RUN 来减小图像文件的大小,例如 RUN apt-get -y update &amp;&amp; apt-get install -y curl
  • 当我删除 CMD 行周围的括号和引号时,运行 docker run myapp 时会返回以下问题:/bin/sh: 1: gulp: not found
  • @CamilleBOUQUET 尝试添加行RUN npm i gulp in dockerfile and rebuild image and test or RUN npm install -g gulp RUN npm link gulp

标签: php docker gulp


【解决方案1】:

首先,你应该使用node image而不是ubuntu,因为这样你以后不需要重新安装它。

我认为您的主要问题是您应该先创建应用目录并复制所有网站内容。

那么你也可以删除VOLUME这对你来说没用。

你可以试试:

FROM node:14

RUN mkdir /app
WORKDIR /app

COPY . /app
RUN apt update
RUN apt install -y php
RUN npm install -g n
RUN n 13.6.0
RUN npm i -g gulp-cli
RUN npm install

ENV PATH=$PATH:/app/node_modules/.bin
ENTRYPOINT [] # to bypass default node
CMD gulp serve:dist

【讨论】:

    【解决方案2】:

    /app/node_modules/.bin/ 不在您的$PATH 中。 要么用ENV PATH=$PATH:/app/node_modules/.bin添加它,要么用路径CMD ["/app/node_modules/.bin/gulp build-production &amp;&amp; /app/node_modules/.bin/gulp serve:dist"]作为gulp前缀。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-09
      • 1970-01-01
      • 2021-11-25
      • 1970-01-01
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 2021-06-13
      相关资源
      最近更新 更多