ERR_CONNECTION_REFUSED with docker container

I am new to Docker and am trying to make a demo Rails application. I made a docker file that looks like this:

FROM ruby:2.2 

# Install apt based dependencies required to run Rails as 
# well as RubyGems. As the Ruby image itself is based on a 
# Debian image, we use apt-get to install those.
RUN apt-get update && apt-get install -y \ 
  build-essential \ 
  nodejs

# Configure the main working directory. This is the base 
# directory used in any further RUN, COPY, and ENTRYPOINT 
# commands.
RUN mkdir -p /app 
WORKDIR /app

# Copy the Gemfile as well as the Gemfile.lock and install 
# the RubyGems. This is a separate step so the dependencies 
# will be cached unless changes to one of those two files 
# are made.
COPY Gemfile Gemfile.lock ./ 
RUN gem install bundler && bundle install --jobs 20 --retry 5

# Copy the main application.
COPY . ./

# Expose port 3000 to the Docker host, so we can access it 
# from the outside.
EXPOSE 3000

# The main command to run when the container starts. Also 
# tell the Rails dev server to bind to all interfaces by 
# default.
CMD ["bundle", "exec", "rails", "server", "-b", "0.0.0.0"]

      

Then I built it (no error):

docker build -t demo . 

      

And then run it (also no errors):

docker run -itP demo
=> Booting Puma
=> Rails 5.1.1 application starting in development on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.8.2 (ruby 2.2.7-p470), codename: Sassy Salamander
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:9292
Use Ctrl-C to stop

      

When I run the command docker ps

in a separate terminal to determine ports, I get:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                     NAMES
55e8224f7c15        demo                "bundle exec rails..."   About an hour ago   Up About an hour    0.0.0.0:32772->3000/tcp   ecstatic_bohr

      

However, when I try to connect to it with http://localhost:32772

either http://192.168.99.100:32772

Chrome or curl, I get a "Connection failed" message.

When I run the application outside of docker on my local machine using a command bundle exec rails server

, it works fine. Please note that I am using Docker Toolbox on my Win7 machine.

What could I be doing wrong?

+3


source to share


2 answers


A combination of the above tricks -

I had to use http://<VM IP ADDRESS>:32772

(localhost: 32772 DOES NOT WORK) AND I had to fix my open port to match TCP listening port 9292.



I still don't understand why the default TCP listening port was 9292 instead of 3000, but I'll cover that separately.

Thanks for the help!

0


source


I spent a couple of hours on this and this thread was really helpful. What I am doing right now is accessing these services via the vm ip address.

You can get your vm address:

docker-machine ls

      



then try to access your service using port 37772 mapped to host, something like this:

http://<VM IP ADDRESS>:32772

      

Hope it helps.

+1


source







All Articles