从Dockerfile运行npm start作为入口点

从Dockerfile运行npm start作为入口点,docker,npm-start,Docker,Npm Start,我正在尝试构建一个dockerfile,在其中我刚刚启动一个http服务器。 我的dockerfile是: FROM ubuntu RUN apt-get update RUN apt-get install -y nodejs && apt-get install -y npm COPY testing /testing RUN cd testing RUN npm install ENTRYPOINT npm start 这里测试的是项目目录,它由index.html文

我正在尝试构建一个dockerfile,在其中我刚刚启动一个http服务器。 我的dockerfile是:

FROM ubuntu

RUN apt-get update
RUN apt-get install -y nodejs && apt-get install -y npm
COPY testing /testing
RUN cd testing
RUN npm install

ENTRYPOINT npm start
这里测试的是项目目录,它由
index.html
文件和
package.json
组成

My package.json是:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "http-server -a 0.0.0.0 -p 5500"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "concurrently": "^5.0.2",
    "http-server": "^0.12.1"
  }
}
在我的本地机器中,服务器工作正常。我认为
cd testing
命令不合适,而且
npm install
没有使用
package.json
文件

docker映像是在映像ID-
6260786586cc

运行映像通过命令时的错误为:

使用指令而不是
cd

WORKDIR testing
Dockerfile中的每条指令在生成期间在单独的容器中执行。所以在构建期间运行
cd
来更改目录是不起作用的

使用指令而不是
cd

WORKDIR testing

Dockerfile中的每条指令在生成期间在单独的容器中执行。所以在构建期间运行
cd
来更改目录是不起作用的

WORKDIR/testing
docker build
替换
RUN-cd-testing
,类似的命令通常写纯文本;你能用纯文本输出替换你的图像文件吗?一般来说,您几乎不应该将终端窗口的屏幕截图粘贴到堆栈溢出帖子中,而是插入您试图显示的内容的实际文本。使用
WORKDIR/testing
docker build
替换
运行cd testing
,类似的命令通常会写出纯文本;你能用纯文本输出替换你的图像文件吗?一般来说,您几乎不应该将终端窗口的屏幕截图粘贴到堆栈溢出帖子中,而是插入您试图显示的内容的实际文本。