我正在尝试使用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 && 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
我很困惑,所以如果有人有解决方案,那就太好了。
最佳答案
首先,您应该使用节点镜像而不是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
关于php - DOCKER:运行gulp-php网站时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62764269/