节点容器无法使用docker for windows运行

时间:2016-07-19 11:47:26

标签: node.js docker

从使用docker toolbox切换到docker for windows后,我无法让我的容器运行。启动容器后,它立即失败并显示状态EXIT 254。这个设置以前使用的是virtualbox,我对这个问题很困惑。构建成功完成。

这是错误:

frontend_1     | npm info it worked if it ends with ok
frontend_1     | npm info using npm@3.8.6
frontend_1     | npm info using node@v5.12.0
frontend_1     | npm ERR! Linux 4.4.15-moby
frontend_1     | npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "run" "dev:no-debug"
frontend_1     | npm ERR! node v5.12.0
frontend_1     | npm ERR! npm  v3.8.6
frontend_1     | npm ERR! path /usr/src/app/package.json
frontend_1     | npm ERR! code ENOENT
frontend_1     | npm ERR! errno -2
frontend_1     | npm ERR! syscall open
frontend_1     |
frontend_1     | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
frontend_1     | npm ERR! enoent ENOENT: no such file or directory, open '/usr/src/app/package.json'
frontend_1     | npm ERR! enoent This is most likely not a problem with npm itself
frontend_1     | npm ERR! enoent and is related to npm not being able to find a file.
frontend_1     | npm ERR! enoent
frontend_1     |
frontend_1     | npm ERR! Please include the following file with any support request:
frontend_1     | npm ERR!     /usr/src/app/npm-debug.log

这是我的Dockerfile:

FROM node:5

WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install
COPY . /usr/src/app/

CMD [ "npm", "run", "dev:no-debug" ]

这是相关的撰写文件设置:

services:
  frontend:
    build:
      context: ./frontend
    volumes:
      - ./frontend:/usr/src/app
      - /usr/src/app/node_modules
    expose:
      - "7777"
    environment:
      - "PORT=7777"
      - "VIRTUAL_PORT=7777"
      - "VIRTUAL_HOST=test.example.com"

编辑:添加目录结构:

C  
└---Users
    |----deepc
         |----docker
              |----myproject
                   |---nginx
                   |---dockergen
                   |---frontend
                        ---package.json, node_modules, src, Dockerfile
                   ---docker-compose.yml

2 个答案:

答案 0 :(得分:1)

在你的compose.yml中你装载了这个卷:

- ./frontend:/usr/src/app

所以基本上你之前在dockerfile中所做的事情是没用的。

如果您的frontend文件夹中没有package.json,那就是问题

答案 1 :(得分:0)

我认为在这样的距离上很难调试,但是你可以尝试像这样构建容器并查看它是否有效吗?

FROM node:5

RUN mkdir -p /usr/src/app
COPY . /usr/src/app

WORKDIR /usr/src/app
RUN npm install
CMD ["npm", "run", "dev:no-debug"]

我认为问题在于:

  

没有这样的文件或目录,打开' /usr/src/app/package.json'

...它告诉我你希望存在的目录,不是!不完全确定你是否需要在复制之前创建目录,但是如果你能给我们构建日志的输出它会有所帮助。