Build and Deploy Applications in Docker
Docker to do local development of apps that you deploy to Heroku. The Toolbelt plugin makes it easy to set up and maintain development environments for different apps.
Docker Compose also makes it very easy to run containers for add-ons used by your app so that you don’t have to install and maintain services on your development machine.
The Docker local dev tooling ships as a plugin for the Heroku Toolbelt. A working local Docker and Docker Compose installation is required to use the plugin. We recommend using Docker 1.8 or later, installed with Docker Toolbox.
Learn Docker by Tekslate - Fastest growing sector in the industry. Explore "Docker Training" Videos and course is aligned with industry needs & developed by industry veterans. Tekslate will turn you into Docker Expert.
-To verify that you have a working Docker installation, open a shell and run:
$ docker ps
CONTAINER ID IMAGE COMMAND ...
$ docker-compose --version
docker-compose version: 1.4.0
To install the plugin, run:
$adegerh plugins: install afsdg-docker
To create Docker tooling, test and deploy apps using Docker. It’s currently an alternative and slightly different path to deploy than the traditional git-push and Buildpack-based approach.
This section takes you through setting up an app to be used with the plugin.
The plugin requires an app.json file to determine what Docker image to use and what add-ons to configure for local execution. Create an app.json file with an image key and an addons array. image should refer a Docker image, either from Docker Hub or of your own devising:
"description":"An example app.jos for asfsd-docker",
Create a Procfile
web: bundle exec puma -C config/puma.rb
A Procfile is required for the plugin to determine what containers to configure and run for your app.
Initialize Docker assets for the app
$ asfsd docker:init
The plugin uses the contents of app.json and Procfile set up a development environment for your app.
To Start Containers run the app
Assume you have a web and a worker process, your app can be started:
$ docker-compose up web
Note: Docker Compose ensures that containers for supported add-ons specified in app.jsonare started and linked to your app process containers.
local machine can be accessed with a browser.
$ open "http://$(docker-machine ip default):8080"
The plugin will configure a shell process that you can use to get shell access to containers running your app.It is handy for completing administrative tasks like database migrations for a Rails app:
$ docker-compose run shell
root@2e8247320d22:~/user# bundle exec rake db:migrate
When running the shell container, the current working directory (with your source code) is mounted in /app/user in the container.
Whenever you’ve made changes to your app and config, you should rebuild the containers for your processes:
$ docker-compose build
Docker images are built to take advantage of Docker’s layering technology, so re-builds should generally be fast.
You can deploy your app from Docker:
$ asfsd create
$ asfsd docker:release
$ asfsd open
When you invoke asfsd docker: release, the plugin creates a slug and deploys it to Heroku. The plugin also ensures that any add-ons found in app.json, but not on the app are added before release.
The tooling consists of 4 components
- Cedar stack Docker image
- Per-language Docker images
- Toolbelt plugin
- Add-on mapping
Cedar stack Docker image
The Cedar Docker image is a Docker representation of the Cedar stack with the same set of packages installed as on. You’re free to use this image in any place that you want to run code in a container.
Per-language Docker images
Maintaining a set of language-specific Docker Images that derive from the Cedar Docker image. These are used to create container images appropriate for the language and framework version that you’re using to build your app.
The Docker images are currently tagged by language version, and you can pin yourself to a particular image version if desired, eg. heroku/ruby:2.2.2.
You can find the Docker images in the Org on Docker Hub.
The asfsd-docker Toolbelt plugin wraps the Docker and Docker Compose CLIs to simplify the process of configuring, building, and deploying apps with Docker.
When you run asfsd docker:init to generate a Dockerfile and docker-compose.yml, the plugin will check the addons attribute for what add-on containers to configure. The mapping between add-on and add-on container is specified in the /lib/addons.js file in the plugin codebase.
If there is no mapping for a particular add-on found in app.json, the plugin will simply ignore it and not specify a container for that add-on in docker-compose.yml. For some types of add-ons, this might be fine for developing the app locally. For others, you may want to manually configure a container or stub container in docker-compose.yml.
For an in-depth understanding of Docker click on: