【发布时间】:2014-11-06 18:54:06
【问题描述】:
运行带有 vagrant 1.6.5 和虚拟框的 windows 7。我有两个码头集装箱; - 节点 - redis
我的部分解决方案正在运行!当我在 VM 外部运行 nodejs 应用程序时,它可以连接到端口 6379 上的 redis 容器。当我在 nodejs docker 容器内运行相同的应用程序时,我得到以下异常:
Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
我可以通过停止 redis 容器来复制外部项目的异常,因此问题看起来与容器如何链接/绑定到 VM 上的内部端口有关。
容器启动如下;
$ docker run -d -p 6379:6379 --name redis myproject/redis
$ docker run --rm -it -P -p 9090:9090 --name node --link redis:rs myproject/node
第二个命令允许我运行和删除图像,以便我可以验证和调试问题。据我了解,容器之间的联系是正确的!
我想删除主机端口 6379,这样您就只能访问 9090 端口,这将暴露 Redis 功能。
示例 nodejs dockerfile;
# DOCKER-VERSION 0.10.0
FROM ubuntu
RUN env
# make sure apt is up to date
RUN apt-get update
# install nodejs and npm
RUN apt-get install -y nodejs npm git git-core
RUN PATH=/usr/bin/node:$PATH
# Bundle app source
ADD src /opt/app/
# use changes to package.json to force Docker not to use the cache
# when we change our application's nodejs dependencies:
ADD src/package.json /tmp/package.json
RUN cd /tmp && npm install
RUN mkdir -p /opt/app && cp -a /tmp/node_modules /opt/app/
RUN cp -a /tmp/node_modules /opt/app/redis
EXPOSE 9090
CMD ["nodejs", "/opt/app/redis/server.js"]`
Any help is appreciated.
Redis dockerfile 示例
# Pull base image.
FROM dockerfile/ubuntu
# Install Redis.
RUN \
cd /tmp && \
wget http://download.redis.io/redis-stable.tar.gz && \
tar xvzf redis-stable.tar.gz && \
cd redis-stable && \
make && \
make install && \
cp -f src/redis-sentinel /usr/local/bin && \
mkdir -p /etc/redis && \
cp -f *.conf /etc/redis && \
rm -rf /tmp/redis-stable* && \
sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf && \
sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf && \
sed -i 's/^\(logfile .*\)$/# \1/' /etc/redis/redis.conf
# Define mountable directories.
VOLUME ["/data"]
# Define working directory.
WORKDIR /data
# Define default command.
ENTRYPOINT ["redis-server"]
# Define default command.
#CMD ["redis-server", "/etc/redis/redis.conf"]
# Expose ports locally on VM
EXPOSE 6379
J
【问题讨论】:
标签: windows node.js redis vagrant virtualbox