運行帶有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
Ĵ