Skip to content

Latest commit

 

History

History
66 lines (37 loc) · 2.36 KB

File metadata and controls

66 lines (37 loc) · 2.36 KB

Ruby runtime Dockerfile

This repository contains Dockerfile of Ruby runtime for Docker's automated build published to the public Docker Hub Registry.

This image is a base image that makes it easy to dockerize standard Rack application.

It can automatically bundle a Rack application and its dependencies with a single line Dockerfile.

This project heavily borrowed code from Google's google/ruby-runtime Docker image.

Base Docker Image

Installation

  1. Install Docker.

  2. Download automated build from public Docker Hub Registry: docker pull dockerfile/ruby-runtime

    (alternatively, you can build an image from Dockerfile: docker build -t="dockerfile/ruby-runtime" github.com/dockerfile/ruby-runtime)

Usage

This image assumes that your application:

  • has a Gemfile and its corresponding Gemfile.lock for bundler, and the Gemfile contains Rack.
  • has config.ru for Rack.
  • listens on port 8080.

When building your application docker image, ONBUILD triggers

  1. Installs gems specified in the Gemfile and leverage docker caching appropriately.
  2. Copy the application sources under the /app directory in the container.

The image uses WEBrick as the application server by default. You can overwrite it by adding mongrel/thin/puma to Gemfile and configuring in your Dockerfile like:

ENV APPSERVER puma

Or you can just overwrite CMD in your Dockerfile like:

CMD ["bundle", "exec", "unicorn", "-c", "unicorn.conf", "config.ru"]
  • Step 1: Create a Dockerfile in your Rack application directory with the following content:
    FROM dockerfile/ruby-runtime
  • Step 2: Build your container image by running the following command in your application directory:
    docker build -t="app" .
  • Step 3: Run application by mapping port 8080:
    APP=$(docker run -d -p 8080 app)
    PORT=$(docker port $APP 8080 | awk -F: '{print $2}')
    echo "Open http://localhost:$PORT/"