How to Create a Tiny Docker Image for your Ruby App

Travis Reeder
Sep 8, 2015 · 2 min read
Image for post
Image for post

I’ve been on a quest to create the smallest possible Docker images for all the things, and here’s how to create a very small image for your Ruby apps (much smaller than I would have thought possible for Ruby). This post will walk you through packaging up a simple Sinatra app into a Docker image that weighs in around 18MB.

All you need for this tutorial is Docker, you don’t even need Ruby installed.

0) The App

That is a Sinatra app that will return a jsonified Hello World response. We need a Gemfile to define our dependencies too:

1) Vendor Dependencies

The iron/ruby-bundle image we’re using here is a special image that has all the libs we need to build native extensions.

2) Test the App

Check http://localhost:8080/ to ensure it’s running correctly. Notice we’re using iron/ruby here, this is a much smaller image than iron/ruby-bundle and has everything we need to run the app. Both of these iron/ruby* images are based on the very small Alpine Linux image (which is totally awesome).

3) Build Docker Image

Now build the image:

4) Test the Docker Image

Once again, check http://localhost:8080/ to ensure it’s running correctly.


You can find the full source code for this example here:

One last thing, if you want to distribute your app, just push it up to Docker Hub:

Then anyone can run your app just by running the same docker run command as above. Technical Blog

The place where we post all the good techie stuff.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store