Reputation: 123
I am using Dockerfile to build docker container for basic rails blog app. here is my Dockerfile
FROM ruby:2.3
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /usr/src/app
COPY Gemfile* ./
RUN bundle install
COPY . .
EXPOSE 8000
CMD rails server -p 8000 -b 0.0.0.0
then I ran this command to build docker image
docker build -t blog .
and here is how I ran container from docker image
docker run -d -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD --net=blog --name app -v $PWD:/usr/src/app -p 8000:8000 blog
after accessing logs from container I got this
docker logs app
=> Booting Puma
=> Rails 5.1.6.1 application starting in development
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.12.0 (ruby 2.3.8-p459), codename: Llamas in Pajamas
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
After googling 2 hours I got some click that its a conflict in rails 5.1 that run tcp://0.0.0.0:3000
in rails. So I switched my application server from PUMA to WEBRICK.
now the docker logs app says:
docker logs app
[2018-12-06 12:30:10] INFO WEBrick 1.3.1
[2018-12-06 12:30:10] INFO ruby 2.3.8 (2018-10-18) [x86_64-linux]
[2018-12-06 12:30:10] INFO WEBrick::HTTPServer#start: pid=8 port=3000
but the application is still not accessible from firefoix/chrom. Please guide if I am doing something wrong. TIA :)
Upvotes: 1
Views: 1018
Reputation: 309
Just an off the cuff suggestion:
Try:
docker run -d -e POSTGRES_USER=$POSTGRES_USER -e POSTGRES_PASSWORD=$POSTGRES_PASSWORD --net=blog --name app -v $PWD:/usr/src/app -p 3000:3000 blog
If you can resolve that perhaps the following is not being applied as you expect.
EXPOSE 8000
CMD rails server -p 8000 -b 0.0.0.0
Upvotes: 4