This article is about Codeship Pro.

Continuous Delivery to Heroku with Docker

Estimated Reading Time: 2 mins

You can find a sample repo for deploying to Heroku with Codeship Pro on Github here.

To make it easy for you to deploy your application to Heroku we’ve built a container that has the Heroku Toolbelt and additional scripts installed. We will set up a simple example showing you how to configure the deployment.


The deployment uses the Heroku Platform API to deploy your application, so no SSH key management is necessary.


Before setting up the codeship-services.yml and codeship-steps.yml file we’re going to create an encrypted environment file that contains the Heroku API Key.

Take a look at our encrypted environment files documentation and add a heroku-deployment.env.encrypted file to your repository. The file needs to contain an encrypted version of the following file:


You can get the Heroku API Key from your Heroku Dashboard or other methods outlined in the Heroku documentation.

Service Definition

In the codeship-services.yml we’re starting a Docker build with the aforementioned Dockerfile.deploy. We can then use the newly created container to deploy our application through the codeship-steps.yml.

  image: codeship/heroku-deployment
  encrypted_env_file: heroku-deployment.env.encrypted
    - ./:/deploy

Deploy Steps

The container has a codeship_heroku deploy command that you need to call with the path to your application, here provided through a host volume in /deploy, and your application name. The script will then check that it has access to the application and deploy it.

By providing the location of the application that should be deployed you can deploy subfolders of your app, or even run different commands on your codebase before deploying it so e.g. assets can already be created.

As the container has the Heroku Toolbelt installed you can use other Heroku commands in further steps, e.g. to run your database migrations.

- service: herokudeployment
  command: codeship_heroku deploy /deploy codeship-heroku-deployment
- service: herokudeployment
  command: heroku run --app codeship-heroku-deployment -- bundle exec rake db:migrate

Need More Help?

Get in touch if you need more help, or post on Stack Overflow using the tag #Codeship.

  • Ask The Helpdesk A Question
  • Code Examples And Sample Projects
    • Was This Article Helpful?