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.
-
Install Docker.
-
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
)
This image assumes that your application:
- has a
Gemfile
and its correspondingGemfile.lock
for bundler, and theGemfile
contains Rack. - has
config.ru
for Rack. - listens on port
8080
.
When building your application docker image, ONBUILD
triggers
- Installs gems specified in the
Gemfile
and leverage docker caching appropriately. - 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/"