2014-02-12 200 views
2

試圖用boot2docker在我的mac os x上運行docker。在mac os x上運行docker with boot2docker?

一切似乎都很好,但我無法運行碼頭圖像。我必須失去一些明顯的東西。

指南我用:

NodeJs Web App
Docker on Mac OS X

我的搬運工文件:

FROM ubuntu:12.04 

# Build dependencies 
RUN apt-get -y update 
RUN apt-get install build-essential -y 
RUN apt-get install curl -y 
# Install NodeJS 
RUN curl -L http://nodejs.org/dist/v0.10.22/node-v0.10.22.tar.gz | tar -xz 
RUN cd /node-v0.10.22 && ./configure 
RUN cd /node-v0.10.22 && make && make install && make clean 
# Global NPM installs 
RUN npm install --silent -g express lodash ejs forever 

RUN mkdir /app 
ADD server.js /app/server.js 
ADD dist /app/dist 
ADD lib /app/lib 
Add test.js /app/test.js 
CMD ["node", "/app/test.js"] 
EXPOSE 8080 

碼頭工人建立輸出:test.js的

@xp (master) ~/work/front-portal: docker build -t front-portal . 
Uploading context 118.7 MB 
Uploading context 
Step 0 : FROM ubuntu:12.04 
---> 9cd978db300e 
Step 1 : RUN apt-get -y update 
---> Using cache 
---> ee9a4b864ffb 
Step 2 : RUN apt-get install build-essential -y 
---> Using cache 
---> e7dd304d6f92 
Step 3 : RUN apt-get install curl -y 
---> Using cache 
---> ded30df6d5c2 
Step 4 : RUN curl -L http://nodejs.org/dist/v0.10.22/node-v0.10.22.tar.gz | tar -xz 
---> Using cache 
---> d132c9cdd09c 
Step 5 : RUN cd /node-v0.10.22 && ./configure 
---> Using cache 
---> 9036f0ce77d2 
Step 6 : RUN cd /node-v0.10.22 && make && make install && make clean 
---> Using cache 
---> c29bcfa1d058 
Step 7 : RUN npm install --silent -g express lodash ejs forever 
---> Using cache 
---> d389052f5e49 
Step 8 : RUN mkdir /app 
---> Using cache 
---> 33576951eb9b 
Step 9 : ADD server.js /app/server.js 
---> Using cache 
---> 2a4aa2230170 
Step 10 : ADD dist /app/dist 
---> Using cache 
---> 4350b786481c 
Step 11 : ADD lib /app/lib 
---> Using cache 
---> 58b0a3850c01 
Step 12 : Add test.js /app/test.js 
---> Using cache 
---> 441d63b47297 
Step 13 : CMD ["node", "/app/test.js"] 
---> Using cache 
---> 013aaa78b0a5 
Step 14 : EXPOSE 8080 
---> Running in 8962747dd91a 
---> 7410cc1bdbed 
Successfully built 7410cc1bdbed 

內容:

var express = require('express'); 

// Constants 
var PORT = 8080; 

// App 
var app = express(); 
app.get('/', function (req, res) { 
    res.send('Hello World\n'); 
}); 

app.listen(PORT) 
console.log('Running on http://localhost:' + PORT); 

Boot2docker運行:

[email protected] (master) ~/work/front-portal: DEBUG=1 docker run front-portal 

[debug] commands.go:2484 [hijack] End of stdout 
[debug] commands.go:2079 End of CmdRun(), Waiting for hijack to finish. 
[email protected] (master) ~/work/front-portal: 

雖然簡單回聲工作:

[email protected] (master) ~/work/front-portal: DEBUG=1 docker run front-portal echo "test" 
test 
[debug] commands.go:2484 [hijack] End of stdout 
[debug] commands.go:2079 End of CmdRun(), Waiting for hijack to finish. 
[email protected] (master) ~/work/front-portal: 

我的節點test.js文件

[email protected] (master) ~/work/front-portal: ./boot2docker status 
[2014-02-12 18:32:50] boot2docker-vm is running. 
[email protected] (master) ~/work/front-portal: 

但我無法啓動泊塢窗是好的:

[email protected] (master) ~/work/front-portal: node test.js 
Running on http://localhost:8080 

[email protected] (master) ~/work/front-portal: DEBUG=1 docker run front-portal ls -al /app/test.js 
-rw-r--r-- 1 501 dialout 232 Feb 12 2014 /app/test.js 
[debug] commands.go:2484 [hijack] End of stdout 
[debug] commands.go:2079 End of CmdRun(), Waiting for hijack to finish. 
[email protected] (master) ~/work/front-portal: 

回答

0

見我不認爲你傳遞正確的參數運行命令。

添加一個「-d」選項讓detached在後臺運行它。如果這不起作用,你可以通過運行以下命令來啓動容器(注意,你的容器可以在你的dockerfile中使用CMD而不是ENTRYPOINT來覆蓋,如果有人有入口點,你將無法使用覆蓋它,並開始與容器bash)。

 
docker run -i -t image_id /bin/bash 

此外,如果您希望能夠擊中服務將要偵聽的端口,則需要執行一些端口轉發。 docker文件中的expose命令將允許docker主機上運行的其他容器能夠訪問該端口,但它不允許主機或boot2docker虛擬機查看它。我想你可能會做一個碼頭檢查$ container_id並找到正確的IP和端口來打,但我發現更容易設置端口轉發。您需要將端口從容器轉發到vm,並從vm轉發到主機。從容器到主機的轉發,使用-p選項:

 
docker run -p :80:8080 image_name 

這將在容器上轉發8080 0.0.0.0:80您boot2docker-VM。要設置轉發從虛擬機到主機,打開VirtualBox和進入的規則,如:

 
open_80 0.0.0.0 :80 _blank_ :80 

這條規則從虛擬機的80端口轉發到本地計算機上的端口80端口轉發可以從設置命令行(就像Andy上面指出的那樣),但是你需要停止boot2docker。