0
我開始對我的第一個碼頭腳本,我試圖調試最後一步,它是非常慢的調試B/C的步驟之前它需要幾分鐘運行,所以如果我有一個錯字,我不得不重新運行整個腳本。更有效地調試碼頭腳本
有沒有更有效的方法來調試碼頭腳本?或者我每次都必須重建整件事情?
#FROM ubuntu:14.04
FROM node:0.10.40
#FROM mongo:2.6.11
# The port we're running the server on
EXPOSE 10645
# Set this as the working directory
WORKDIR /myproject/hapi
# Move the myproject files to /myproject in the docker container
ADD . /myproject/hapi
# Install the server dependencies
RUN pwd && ls -al && npm install
# Start everything up
CMD npm start
日誌輸出:
^CR5033505:myproject m089269$ docker build -t myproject-hapi .
Sending build context to Docker daemon 932.2 MB
Step 0 : FROM node:0.10.40
---> a7d8016a6fdb
Step 1 : EXPOSE 10645
---> Running in ebc4f8ebbf7b
---> 701320586e6a
Removing intermediate container ebc4f8ebbf7b
Step 2 : WORKDIR /myproject/hapi
---> Running in 1998f97b252a
---> 1414baf38920
Removing intermediate container 1998f97b252a
Step 3 : ADD . /myproject/hapi
---> c80e665da20b
Removing intermediate container f6904fab79ce
Step 4 : RUN pwd && ls -al && npm install
---> Running in a3ef28ed70ae
/myproject/hapi
total 68
drwxr-xr-x 9 root root 4096 Oct 30 18:35 .
drwxr-xr-x 3 root root 4096 Oct 30 18:35 ..
-rw-r--r-- 1 root root 509 Apr 10 2015 .editorconfig
drwxr-xr-x 8 root root 4096 Oct 30 18:33 .git
-rw-r--r-- 1 root root 491 Oct 20 15:09 .gitignore
drwxr-xr-x 8 root root 4096 Aug 19 14:51 .idea
-rw-r--r-- 1 root root 1781 Apr 10 2015 .jscsrc
-rw-r--r-- 1 root root 6164 Apr 10 2015 .tfignore
-rw-r--r-- 1 root root 430 Oct 30 18:33 Dockerfile
-rw-r--r-- 1 root root 371 Oct 30 18:16 Dockerfile-client
-rwxr-xr-x 1 root root 1374 Oct 30 15:15 README.md
drwxr-xr-x 5 root root 4096 Oct 21 21:18 ab-testing-deploy
drwxr-xr-x 3 root root 4096 Oct 30 15:15 build
drwxr-xr-x 14 root root 4096 Oct 30 15:15 client
drwxr-xr-x 2 root root 4096 Apr 10 2015 githooks
drwxr-xr-x 10 root root 4096 Oct 30 15:15 hapi
npm ERR! install Couldn't read dependencies
npm ERR! Linux 4.1.10-boot2docker
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.10.40
npm ERR! npm v2.14.1
npm ERR! path /myproject/hapi/package.json
npm ERR! code ENOPACKAGEJSON
npm ERR! errno 34
npm ERR! package.json ENOENT, open '/myproject/hapi/package.json'
npm ERR! package.json This is most likely not a problem with npm itself.
npm ERR! package.json npm can't find a package.json file in your current directory.
npm ERR! Please include the following file with any support request:
npm ERR! /myproject/hapi/npm-debug.log
The command '/bin/sh -c pwd && ls -al && npm install' returned a non-zero code: 34
您實際上也可以從任何圖層開始,您不必從基本圖像開始。因此,使用你的示例輸出,'---> c80e665da20b'這一行意味着'c80e665da20b'層是成功的,你可以使用:'docker run -ti c80e665da20b bash'從該層運行,然後手動執行下一步,直到它作品。 – dnephin
一旦你有它的工作,你也可以重新安排你的'Dockerfile'和只有'ADD'列出依賴項('package.json')的文件,然後運行'npm install'和'ADD。/myproject/hapi'at在最後。這樣,當你的依賴關係改變時,你只需要等待'npm install'步驟,而不是任何代碼改變。 – dnephin
@dnephin很好!我不知道你可以這樣做。 –