我fig
用来部署我的Node.js
应用程序。
fig.yml
web:
build: .
command: node app.js
links:
- db
ports:
- "1337:1337"
db:
image: dockerfile/mongodb
运行fig run db env
给了我以下环境变量:
DB_PORT=tcp://172.17.0.29:27017
DB_PORT_27017_TCP=tcp://172.17.0.29:27017
DB_PORT_27017_TCP_ADDR=172.17.0.29
DB_PORT_27017_TCP_PORT=27017
DB_PORT_27017_TCP_PROTO=tcp
DB_PORT_28017_TCP=tcp://172.17.0.29:28017
DB_PORT_28017_TCP_ADDR=172.17.0.29
DB_PORT_28017_TCP_PORT=28017
DB_PORT_28017_TCP_PROTO=tcp
DB_NAME=/pos_db_run_3/db
我的应用Dockerfile
看起来像这样
# Pull base image.
FROM dockerfile/nodejs
# install mongo client
RUN apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
RUN echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | tee /etc/apt/sources.list.d/mongodb.list
RUN apt-get update
RUN apt-get install -y dnsutils
RUN apt-get install -y mongodb-org-shell
# copy the source files into the image
COPY . /data/myapp
# Define working directory.
WORKDIR /data/myapp
# Install dependencies
RUN npm install
# Create default database and user
RUN mongo $DB_PORT < seed-mongo
RUN node/seed.js
EXPOSE 1337
# Define default command.
CMD ["bash"]
但是构建失败了RUN mongo $DB_PORT < seed-mongo
MongoDB shell version: 2.6.5
connecting to: test
2014-11-20T20:47:59.193+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-20T20:47:59.195+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
Service 'web' failed to build: The command [/bin/sh -c mongo $DB_PORT < seed-mongo] returned a non-zero code: 1
根据无花果文档,我最好像db
我尝试过的那样简单地引用数据库
RUN mongo db < seed-mongo
但这给了我
MongoDB shell version: 2.6.5
connecting to: db
2014-11-20T21:08:11.154+0000 warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2014-11-20T21:08:11.156+0000 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed
所以我RUN host db
在那里注入了一个,只是为了看看是否db
真的是一个主机名。不,尽管上面的文档不是。
Step 10 : RUN host db
---> Running in 73b4dc787c79
Host db not found: 3(NXDOMAIN)
Service 'web' failed to build: The command [/bin/sh -c host db] returned a non-zero code: 1
所以我很难过。
我应该如何与在我的链接容器中mongo
运行的实例交谈?Docker