2017-10-09 144 views
1

我想dockerize我的Angular應用程序,但是,我在運行容器時遇到問題。啓動容器導致錯誤

這裏是我的Dockerfile:

FROM node:8.6-alpine 

RUN mkdir /app 

WORKDIR /app 

COPY package.json ./ 
COPY .angular-cli.json ./ 
COPY tsconfig.json ./ 
COPY tslint.json ./ 
COPY src/ ./src/ 

RUN yarn install && yarn global add @angular/cli 

EXPOSE 4200 

ENTRYPOINT ["./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200"] 

這是我的命令,我如何運行:在控制檯

$ docker run -p 4200:4200 my-notes 

和錯誤,當我開始我的容器:

container_linux.go:262: starting container process caused "exec: \"./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200\": stat ./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200: no such file or directory" 
docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "exec: \"./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200\": stat ./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200: no such file or directory". 
ERRO[0000] error waiting for container: context canceled 

我試着設置ENTRYPOINT只需ng serve,然後容器工作,並且不記錄錯誤在控制檯中,但我無法從我的瀏覽器運行應用程序(頁面不可用)

回答

1

ENTRYPOINT command接受參數列表。您只放置了一個參數,其中包含命令參數。

我建議您更換ENTRYPOINT出現這樣的事情 - 分隔參數

ENTRYPOINT ["./node_modules/angular-cli/bin/ng", "serve", "--host", "0.0.0.0", "--port", "4200"] 

從「沒有這樣的文件」的錯誤你貼出來,我猜,碼頭工人正在嘗試找到一個名爲"./node_modules/angular-cli/bin/ng serve --host 0.0.0.0 --port 4200"的文件,該文件顯然不存在:)當您刪除其他參數時,docker能夠找到該文件。

+0

它的工作,但作爲第一個參數,我不得不通過「ng」。非常感謝! – TheOpti

+0

啊 - 非常好:)是的,你可能需要在你的PATH中有'ng'才能工作 - 否則提供'ng'的絕對路徑也應該工作。 – Lix