DOCKER:运行gulp.php网站时出错



我正在尝试使用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

应用程序文件夹包含我所有的php文件:

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

我的gulpfile.js包含了编译和构建我的网站的所有任务。它运行良好。由于我创建的任务的名称,我用来运行的命令是gulp build-production && 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 

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

首先,应该使用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

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

最新更新