B
B
Bogdan2018-05-01 11:46:46
ruby
Bogdan, 2018-05-01 11:46:46

Nginx/Passenger + Rails in a container?

Hello. Tell me please. I have a configured server under CentOS, according to the instructions
Now I want to transfer it to a Docker container. As if the question is that according to these instructions, I myself Nginx starts the Rails server with Passenger.

server {
    listen 80;
    server_name yourserver.com;

    # Tell Nginx and Passenger where your app's 'public' directory is
    root /var/www/myapp/code/public;

    # Turn on Passenger
    passenger_enabled on;
    passenger_ruby /path-to-ruby;
}

And according to the docker ideology, each container is now one server, and now Rails and Nginx need to be separated, and then how to do it right so that Nginx starts the Rails server, or how to do it in general?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2018-05-01
@bogdan_uman

The Passenger code is in one container, nginx in another and will reverse to the first one. It is advisable to put the static separately so that you can feed nginx.
Minimum Dockerfile:

FROM ruby:2.5-alpine
ADD . /app
WORKDIR /app
RUN bundle install
CMD ["bundle", "exec", "passenger", "start"]

docker-compose.yml:
version: '2'
services:
  passenger:
    build: ./
    restart: always
    #ports:
    #  - 3000:3000 (для дебага)

  nginx:
    image: nginx:mainline-alpine
    restart: always
    volumes:
      #- ./nginx.conf:/etc/nginx/nginx.conf
      - ./nginx-site.conf:/etc/nginx/conf.d/passenger.conf
      #- /path/to/static/:/path/in/container/

In nginx-site.conf instead of passenger directives (you may need headers for proxying X-Real-IP type):proxy_pass http://passenger:3000;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question