title: Exposing Redis DB docker container to a NodeJS docker container
body: <p>Running windows 7 with vagrant 1.6.5 and virtual box. I've got two docker containers;
  - nodejs
  - redis</p>
  
  <p>Part of my solution is running and working! The nodejs app when I run it outside the VM can connect to the redis container on port 6379. When I run the same app inside the nodejs docker container I get the following exception:</p>
  
  <pre><code>Redis connection to 127.0.0.1:6379 failed - connect ECONNREFUSED
  </code></pre>
  
  <p>I can replicate the exception on the external project by stopping the redis container so the issue looks like its related to how the containers are linked/binding on internal ports on the VM.</p>
  
  <p>The containers are started as follows;</p>
  
  <pre><code>$ 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
  </code></pre>
  
  <p>The second command allows me to run and delete the image so that I can validate and debug the issue. From my understanding the linkage between the containers is correct! </p>
  
  <p>I want to remove the host port 6379 so you can only hit the 9090 port which will expose Redis functionality.</p>
  
  <p>Sample nodejs dockerfile;</p>
  
  <pre><code># 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 &amp;&amp; npm install
  RUN mkdir -p /opt/app &amp;&amp; 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.
  </code></pre>
  
  <p>Sample Redis dockerfile</p>
  
  <pre><code># Pull base image.
  FROM dockerfile/ubuntu
  
  # Install Redis.
  RUN \
    cd /tmp &amp;&amp; \
    wget http://download.redis.io/redis-stable.tar.gz &amp;&amp; \
    tar xvzf redis-stable.tar.gz &amp;&amp; \
    cd redis-stable &amp;&amp; \
    make &amp;&amp; \
    make install &amp;&amp; \
    cp -f src/redis-sentinel /usr/local/bin &amp;&amp; \
    mkdir -p /etc/redis &amp;&amp; \
    cp -f *.conf /etc/redis &amp;&amp; \
    rm -rf /tmp/redis-stable* &amp;&amp; \
    sed -i 's/^\(bind .*\)$/# \1/' /etc/redis/redis.conf &amp;&amp; \
    sed -i 's/^\(daemonize .*\)$/# \1/' /etc/redis/redis.conf &amp;&amp; \
    sed -i 's/^\(dir .*\)$/# \1\ndir \/data/' /etc/redis/redis.conf &amp;&amp; \
    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
  </code></pre>
  
  <p>J</p>