In the previous articles we discussed two important things:

In this article, let’s leave Elixir and focus on Docker and CircleCI, this time with Heroku deployment.

Docker registry

To sum up the official documentation briefly:

A registry is a storage holding named Docker images, available in different tagged versions.

holding named Docker images, available in different tagged versions. The Docker registry lets you distribute Docker images.

Docker images. You should use the registry if you want to control where your images are being stored.

Users looking for a zero maintenance, ready-to-go solution are encouraged to head-over to the Docker Hub.

Users interact with a registry by using docker push and pull commands.

Now you know what the registry is, let’s jump to what Heroku offers us in this area.

Heroku Container Registry

Support for deploying Docker-based apps to Heroku is in beta. But I use that successfully on production with multiple apps and I haven’t had any major problems so far with it.

To integrate your Heroku app with Docker you need to have Heroku CLI and Docker engine installed locally. Then, you are able to run the following command:

heroku plugins:install heroku-container-registry

Which will add Heroku Container Registry plugin to your account. You can verify the installation by executing:

heroku container:login

Now, you are ready to build and push your Docker image by a simple command:

heroku container:push

Your app should be up and running, verify the entire process by typing:

heroku open -a APP_NAME

CircleCI deployment

CircleCI 1.0 offers support for running Docker within build containers. CircleCI pre-installs Docker Engine in the Linux build images.

Firstly, let’s see how the complete circle.yml file looks like:

Although it’s pretty easy to understand, there are a few things that need to be commented here:

Even though CircleCI pre-installs Docker Engine, we need to enable it explicitly by simply adding Docker as a required service. We cache ~/docker directory to save some time when building subsequent Docker images. We don’t use Heroku Container Registry plugin here, instead, we do everything manually:

We log into the registry using our Heroku email as an email and a username , and Heroku API key as the password

and a , and Heroku API key as the Intermediate images aren’t handled well in the CircleCI container so using --rm=false with Docker build prevents a bunch of annoying errors.

with Docker build prevents a bunch of annoying errors. We use usual docker build and docker push commands to build and deploy our image.

Dockerfile

Are there any required changes regarding Dockerfile ? Not really. The only thing to keep in mind is to set WORKDIR there because Heroku doesn’t let us use sudo command in root directory. Everything else should remain the same.

Subscribe to get the latest content immediately

https://tinyletter.com/KamilLelonek

Summary

You are ready to go with deploying Docker containers directly to Heroku using CircleCI. The entire setup is pretty simple to configure and to start working with. Once you have Heroku with Docker configured, you are able to change platform (e.g. AWS Beanstalk) at any time you need.