Skip to content

Instantly share code, notes, and snippets.

@itsprdp
Last active March 24, 2017 09:08
Show Gist options
  • Save itsprdp/486e727de5a32d48ed34f93fd23dd02f to your computer and use it in GitHub Desktop.
Save itsprdp/486e727de5a32d48ed34f93fd23dd02f to your computer and use it in GitHub Desktop.
Ruby 2.2.0 + Nginx + Passenger + Pagespeed base image

Docker base image for Rails applications

Installed packages
  • ruby-2.2.6
    • path: /usr/local/bin/ruby
    • gem_path: /usr/local/lib/ruby/gems/2.2.0/bin
  • nginx
    • version: 1.11.0
    • path: /usr/local/nginx/sbin/nginx
    • src: /usr/local/nginx
    • modules:
      • passenger
        • version: 4.0.57
        • path: /usr/local/lib/ruby/gems/2.2.0/gems/passenger-4.0.57/
        • Note: You can get the passenger path by running $(passenger-config --root)
      • pagespeed

Passenger Nginx config

  ...

  http {
    ...

    default_type application/octet-stream;
    include /usr/local/nginx/conf/mime.types;

    pagespeed on;
    pagespeed FileCachePath /rubyapp/tmp/ngx_pagespeed_cache;

    passenger_root /usr/local/lib/ruby/gems/2.2.0/gems/passenger-4.0.57/locations.ini;
    passenger_ruby /usr/local/bin/ruby;

    ...
  }

  ...

Nginx commands:

  1. start nginx with custom config file
    /usr/local/nginx/sbin/nginx -c $APP_DIR/config/nginx.conf
  2. Check nginx status or stop or to reload
    /usr/local/nginx/sbin/nginx -s (stop|status|reload)
System Info

Operating System/Base Image: Debian Jessie
User: root
Home directory: /rubyapp

FROM debian:latest
MAINTAINER PG <itsprdp@gmail.com>
RUN apt-get update -qq \
&& apt-get install -y build-essential curl less vim g++ libcurl4-openssl-dev zlib1g-dev \
libpcre3 libpcre3-dev unzip wget sudo libxml2-dev libxslt1-dev nodejs git libmysqlclient-dev \
libssl-dev libreadline-dev libgdbm-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN wget https://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.6.tar.gz \
&& tar -xf ruby-2.2.6.tar.gz && cd ruby-2.2.6 \
&& ./configure && make && make install && rm -rf ruby-2.2.6*
RUN gem install bundler --no-ri --no-rdoc \
&& gem install passenger -v '4.0.57' --no-ri --no-rdoc
# Build passenger module for ruby and build passenger agents
# Get the passenger path $(passenger-config --root)
RUN passenger-config build-native-support \
&& passenger-config about make-locations-ini > $(passenger-config --root)/locations.ini
# Google PageSpeed nginx module
# https://modpagespeed.com/doc/build_ngx_pagespeed_from_source
RUN curl -f -L -sS https://ngxpagespeed.com/install > setup_ngx_with_pagespeed.sh \
&& chmod +x setup_ngx_with_pagespeed.sh \
&& ./setup_ngx_with_pagespeed.sh --nginx-version latest -a '--add-dynamic-module=$(passenger-config --root)/ext/nginx' \
&& rm setup_ngx_with_pagespeed.sh && rm -rf ~/nginx-1.11.10 ~/ngx_pagespeed-latest-stable
RUN apt-get -y purge --auto-remove g++ unzip wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV APP_HOME /rubyapp
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment