> ## Content Index
> Fetch the complete content index at: https://blog.neighborhoodcuts.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Building and Deploying Ruby Docker Images with CircleCI and Heroku
- URL: https://blog.neighborhoodcuts.com/building-and-deploying-ruby-docker-images-with-circleci-and-heroku/
- Published: 2017-06-20T01:21:45.000Z
- Updated: 2026-11-10T20:25:35.000Z
- Author: Simon Taranto
- Tags: Engineering, #Migrated-1794262677729, #wp, #wp-post, #Import 2026-11-09 22:19

Heroku makes it dead simple to deploy and operate apps; Docker makes it even easier! Heroku has a [Docker runtime](https://devcenter.heroku.com/articles/container-registry-and-runtime?ref=blog.neighborhoodcuts.com) in beta.

This article will review how to setup a simple Ruby app to build and deploy as a Docker container on Heroku using [CircleCI](https://circleci.com/?ref=blog.neighborhoodcuts.com).

## The app we'll be using

We run a dashboard for internal use with a range of widgets that give us data about various events in the company and application. We use [Smashing](https://github.com/Smashing/smashing?ref=blog.neighborhoodcuts.com), which is a Sinatra-esque Ruby framework for building dashboards.

## Setting up the Dockerfile

Heroku recently released their new [Heroku-16](https://devcenter.heroku.com/articles/heroku-16-stack?ref=blog.neighborhoodcuts.com) stack. We'll base our image off it. We'll then install required system dependencies so we can install gems. Next we'll install `bundler` and our gem dependencies. From there we'll give the container a default `CMD` that will boot up the dashboard.

```
FROM heroku/heroku:16

RUN apt-get update -qq && apt-get install -y \
  build-essential \
  libpq-dev \
  nodejs \
  ruby-dev
RUN mkdir /my_dashboard
WORKDIR /my_dashboard
ADD Gemfile /my_dashboard/Gemfile
ADD Gemfile.lock /my_dashboard/Gemfile.lock
RUN gem install bundler
RUN bundle install
ADD . /my_dashboard
CMD rackup --port=$PORT

```

In order to build this image, we'll need to install Docker. Assuming we're on Mac, we'll head over [here](https://docs.docker.com/docker-for-mac/install/?ref=blog.neighborhoodcuts.com#download-docker-for-mac) to install Docker. Once we've installed Docker, we'll `cd` into the project directory and run the following commands:

```
docker build . -t my_dashboard
docker run -p 9292:9292 my_dashboard rackup

```

Now we should have the app up and running!

If everything looks good, deploy the image manually to Heroku using the following commands.

```
heroku plugins:install heroku-container-registry
heroku container:login
heroku container:push
heroku open

```

Our dashboard is alive on Docker!

## Building and deploying via CI

We want to be able to deploy our app from our continuous integration system instead of pushing manually. We'll use CircleCI.

Add a `circle.yml` file to our project with the following config.

```
machine:
  services:
    - docker

dependencies:
  override:
    - echo "no deps"

test:
  post:
    - echo "yay - no tests"

deployment:
  production:
    branch: master
    commands:
      - docker build -t my_dashboard .
      - docker login --email=_ --username=_ --password=$HEROKU_TOKEN registry.heroku.com
      - docker tag my_dashboard:latest registry.heroku.com/my_dashboard/web
      - docker push registry.heroku.com/my_dashboard/web

```

We'll need to configure an environment variable for `HEROKU_TOKEN` (taken from our Heroku dashboard) so Circle can authenticate against the Heroku container registry.

Upon the next successful `master` build, we should see our image be built and then deployed to Heroku all from CI!

## Open questions

Working with Docker raises some open questions around developer workflow, especially for more complicated applications (e.g. those with a separate worker process).

Here are some of the issues:

- How do we run tests? Do we build an image (including test gems) and run tests against it?
- How would we manage compiling assets if we needed to?
- How do we ergonomically deploy multiple processes (assuming one process per container)?

## Further reading

This post is just a taste of working with Docker. If you're interested, check out the following resources to learn more.

- Docker [video intro](https://training.docker.com/introduction-to-docker?ref=blog.neighborhoodcuts.com)
- [Written tutorial](https://www.toptal.com/devops/getting-started-with-docker-simplifying-devops?ref=blog.neighborhoodcuts.com) on getting started
- Introduction to [Docker Compose](https://docs.docker.com/compose/overview?ref=blog.neighborhoodcuts.com) if you want to have multiple containers coordinating with each other
- Overview of [using registries](https://docs.docker.com/registry/?ref=blog.neighborhoodcuts.com#next)