运行带有vagrant 1.6.5和虚拟框的Windows 7。我有两个码头集装箱; - nodejs - redis将Redis DB泊坞窗容器暴露给NodeJS泊坞窗容器
我的部分解决方案正在运行并正在运行!该应用程序的NodeJS当我运行的VM外部可以连接到Redis的容器上的端口6379.当我运行的泊坞窗的NodeJS容器出现以下异常中相同的应用程序:
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功能。
Sample 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
Ĵ