Unable to expose the application

Hi, for some reasons I’m unable to expose the application to my network even using -P.

Here is my Dockerfile:

FROM ruby:2.5.1
RUN apt-get update && apt-get install -qq -y build-essential libpq-dev postgresql-client curl apt-utils apt transport-https imagemagick --fix-missing --no-install-recommends
RUN bundle config --global frozen 1
WORKDIR /app
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
CMD bundle exec foreman start

I start it:

docker container run -P -e RAILS_LOG_TO_STDOUT=1 directory:latest

It starts ok, no errors:

11:21:40 web.1     | Puma starting in single mode...
11:21:40 web.1     | * Version 3.12.0 (ruby 2.5.1-p57), codename: Llamas in Pajamas
11:21:40 web.1     | * Min threads: 5, max threads: 5
11:21:40 web.1     | * Environment: development
11:21:40 web.1     | * Listening on tcp://0.0.0.0:3000
11:21:40 web.1     | Use Ctrl-C to stop

If I point my browser to localhost:3000 or 0.0.0.0:3000 it connects to nothing (Unable to connect), pretty sure nothing is answering to that port. If I curl 3000 from inside the container I can see the response I’m expecting.

I’ve tried 3000:3000 as well, same. Interesting fact, if I hist ctrl+c the container doesn’t stop.

Can someone help me? I’m out of guesses

ngw

Hi,

The -P flag exposes all exposed ports, but in your Dockerfile you don’t expose any ports.
You can export ports in your Dockerfile with

EXPOSE 3000

and use -P

or you can use

-p 127.0.0.1:3000:3000

to expose port 3000 inside the container to port 3000 on you localhost interface

once this works you can use

-p 0.0.0.0:3000:3000

to expose the port to the outside