title: Docker, can't reach "rails server" development from localhost:3000 using docker flag -p 3000:3000
body: <p>I'm trying to use docker with rails, building an entire stack inside one container. My endgoal is to have an nginx/memcached/unicorn/rails/postgres stack with runit as the process manager. So far I have my app, ruby, and postgres installed. At this point I'm trying to test if everything is working correctly before I move on to nginx/memcached/unicorn.<br>
  Here's my dockerfile:</p>
  
  <pre><code>FROM ubuntu:trusty
  
  ADD . /app
  
  # Update repos
  RUN apt-get update
  
  # General 
  RUN apt-get install -y git curl software-properties-common python-software-properties ssh
  
  # Install ruby (taken from https://gist.github.com/konklone/6662393)
  RUN \curl -Lk https://get.rvm.io | bash -s stable
  RUN /bin/bash -l -c "rvm requirements"
  RUN /bin/bash -l -c "rvm install 2.1.1"
  ENV PATH /usr/local/rvm/gems/ruby-2.1.1/bin:/usr/local/rvm/rubies/ruby-2.1.1/bin:$PATH
  RUN gem install bundler --no-ri --no-rdoc
  
  # Install nodejs (rails js runtime)
  RUN apt-get install -y nodejs
  
  # Install postgresql (adapted from https://wiki.postgresql.org/wiki/Apt)
  RUN echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -sc)-pgdg main"
  RUN curl https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
  RUN apt-get update
  RUN apt-get install -y postgresql-9.3 postgresql-client-9.3 postgresql-contrib-9.3
  
  # Setup postgresql
  RUN mkdir /pgsql &amp;&amp; chown postgres /pgsql
  USER postgres
  ENV PATH $PATH:/usr/lib/postgresql/9.3/bin/
  RUN initdb -E UTF8 -D /pgsql/data
  USER root
  
  # Needed for pg gem (from http://stackoverflow.com/a/20754173)
  RUN apt-get install -y libpq-dev
  </code></pre>
  
  <p>Then I create a container with the following command</p>
  
  <pre><code>docker run -it -p 3000:3000 *dockerfile_image* /bin/bash -l
  </code></pre>
  
  <p>Inside of that container I set up postgresql as a background job and run rails s</p>
  
  <pre><code>$ sudo -u postgres /usr/lib/postgresql/9.3/bin/postgres -D /pgsql/data
  ^z
  $ bg
  $ sudo -u postgres /usr/bin/psql -c "create role *appname* login createdb"
  $ cd /app
  $ bundle &amp;&amp; rake db:create db:migrate
  $ rails s
  =&gt; Booting WEBrick
  =&gt; Rails 4.1.0 application starting in development on http://0.0.0.0:3000
  =&gt; Run `rails server -h` for more startup options
  =&gt; Notice: server is listening on all interfaces (0.0.0.0). Consider using 127.0.0.1 (--binding option)
  =&gt; Ctrl-C to shutdown server
  ....
  </code></pre>
  
  <p>But as the title states, I can't connect from localhost:3000.
  I've also tried </p>
  
  <ul>
  <li>trying to connect from 0.0.0.0:3000</li>
  <li>leaving the -p 3000:3000 and trying to connect from <em>container_ip</em>:3000</li>
  <li>EXPOSE 3000 in the dockerfile, using docker ps to find the mapped port and trying localhost:<em>mapped_port</em></li>
  </ul>
  
  <p>Also I don't know if it matters but I'm using boot2docker on OSX.</p>