• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

How to Build and Deploy 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.

-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:

{
 "name":"Example Name",
"description":"An example app.jos for asfsd-docker",
"image":"asfsd/ruby",
"addons":["asfsd-postgresql"]
}

Procfile

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
Wrote Dockerfile
Wrote docker-compose.yml

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"

Shell access:

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
Building shell...
..
root@2e8247320d22:~/user# bundle exec rake db:migrate

When running the shell container, the current working working directory (with your source code) is mounted in /app/user in the container.

Rebuild containers

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.

Deploying

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.

Overview technically

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 any place that you want to run code in a  container.

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.

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.

Toolbelt plugin

The asfsd-docker Toolbelt plugin wraps the Docker and Docker Compose CLIs to simplify the process of configuring, building and deploying  apps with Docker.

Add-on mapping

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 code base.

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 indepth understanding of Docker click on

Summary
Review Date
Reviewed Item
How to Build and Deploy in Docker
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on How to Build and Deploy in Docker"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.