Docker rails connection refused

I ve been playing with docker and fig for a rails application being built for scripted. This is my first time using docker in an actual project and I came across an issue that doesn’t readily have an answer out there even though in retrospect the answer was staring at me in the face.

Essentially after getting the containers built and running, I was not able to connect to the docker container at all. Everytime I tried connecting to the container, I would get a connection refused error.

~/P/r/schoolio ❯❯❯ boot2docker ip

The VM's Host only interface IP address is:

~/P/r/schoolio ❯❯❯ curl -i
curl: (7) Failed to connect to port 3000: Connection refused

My Dockerfile looks like

# Choose the official Ruby 2.1.2 image as our starting point
FROM ruby:2.1.2

# Run updates
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev sudo openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison nodejs

RUN useradd -ms /bin/bash deployer
RUN echo "deployer:deployer" | chpasswd && adduser deployer sudo
RUN mkdir -p /home/deployer/schoolio && chown -R deployer:deployer /home/deployer/schoolio
ENV HOME /home/deployer
RUN echo "%sudo        ALL=NOPASSWD: ALL" >> /etc/sudoers
USER deployer

RUN ruby -ropenssl -e 'puts OpenSSL::X509::DEFAULT_CERT_FILE'

# Set up working directory
WORKDIR /home/deployer/schoolio

# RUN sudo gem update --system

# Set up gems
ADD Gemfile /home/deployer/schoolio/Gemfile
ADD Gemfile.lock /home/deployer/schoolio/Gemfile.lock
RUN sudo chown -R deployer /home/deployer/schoolio/*
RUN bundle install

ADD . /home/deployer/schoolio

My fig.yml looked like this:

  image: postgres
    - "5432"

# redis:
#   image: redis
#   ports:
#     - "6379"

  build: .
  command: rails s
    - .:/home/deployer/schoolio
    - "3000:3000"
    - db
    # - redis

When I tried to run, the server started fine but wouldnt let me connect to it at all.

~/P/r/schoolio ❯❯❯ fig up
Recreating schoolio_db_1...
Recreating schoolio_web_1...
Attaching to schoolio_db_1, schoolio_web_1
db_1  | LOG:  database system was shut down at 2014-12-07 13:50:32 UTC
db_1  | LOG:  autovacuum launcher started
db_1  | LOG:  database system is ready to accept connections
web_1 | => Booting Puma
web_1 | => Rails 4.2.0 application starting in development on http://localhost:3000
web_1 | => Run `rails server -h` for more startup options
web_1 | => Ctrl-C to shutdown server
web_1 | Puma 2.10.2 starting...
web_1 | * Min threads: 0, max threads: 16
web_1 | * Environment: development
web_1 | * Listening on tcp://localhost:3000

~/P/r/schoolio ❯❯❯ curl -i
curl: (7) Failed to connect to port 3000: Connection refused

Docker showed two containers running and an the correct ports

~/P/r/schoolio ❯❯❯ docker ps
CONTAINER ID        IMAGE                 COMMAND                CREATED             STATUS              PORTS                     NAMES
8e0b1fe500b8        schoolio_web:latest   "rails s"              14 seconds ago      Up 13 seconds>3000/tcp    schoolio_web_1      
0283bd6147c6        postgres:9            "/docker-entrypoint.   16 seconds ago      Up 15 seconds>5432/tcp   schoolio_db_1     

After searching far and wide, I stumbled upon this issue on github and that pretty much solved the issue. All that need to be changed was the rails server startup command. specifically in the fig.yml,

  command: bundle exec rails s -b

The problem was that rails was trying to listen on localhost while the server was running on . Hope this helps someone else out there.