Dockerator for Elixir

Hex.pmHex.pm

Tool for turning Elixir apps into Docker images without a pain.

Rationale

One may say that creating a Dockerfile for an Elixir app is so easy that creating a separate tool for such purpose is an overkill.

However, that might be not that easy if:

In such cases Dockerator will save you a lot of time.

Features

Internally it uses Distillery for building the actual release.

Prerequisities

You need to use Elixir >= 1.4.

You need to have on your computer a Docker installation. The docker command should be callable without sudo.

Usage

Add it to the dependencies, by adding the following the deps in mix.exs:

def deps do
  [
    {:dockerator, "~> 1.2", runtime: false},
  ]
end

Moreover add the key :dockerator_target_image to the app with name of the target Docker image.

Then fetch the dependencies:

mix deps.get

Create release configuration (if it is not present yet):

mix release.init

It will create rel/ directory, add it to git:

git add rel/

Then you can just call the following command each time you need to assemble a Docker image tagged as latest:

mix dockerate

If you want to make the actual release, please increase version in the mix.exs (potentially you want to also tag the code in git) and then run

mix dockerate release

The Docker image will use version from mix.exs as a tag.

You probably want to also change the Mix environment, just prefix the commands with MIX_ENV=env, e.g.:

MIX_ENV=prod mix dockerate release

Configuration

You can use the following settings in the project of the mix.exs in order to configure Dockerator:

Example

For example your mix.exs might look like this after the changes:

defmodule MyApp.Mixfile do
  use Mix.Project

  def project do
    [app: :my_app,
     version: "0.1.0",
     elixir: "~> 1.4",
     build_embedded: Mix.env == :prod,
     start_permanent: Mix.env == :prod,
     deps: deps(),
     dockerator_ssh_agent: true,
     dockerator_build_extra_docker_commands: [
       "RUN apt-get update && apt-get install somepackage",
     ],
     dockerator_release_extra_docker_commands: [
       "EXPOSE 4000",
       "RUN apt-get update && apt-get install somepackage",
     ],
     dockerator_source_dirs: ["config", "lib", "rel", "priv", "web", "extra"],
     dockerator_base_image: [build: "elixir:1.4.5", release: "ubuntu:xenial"],
     dockerator_target_image: "myaccount/my_app",
    ]
  end

  def application do
    [extra_applications: [:logger], mod: {MyApp, []}]
  end

  defp deps do
    [
      {:dockerator, "~> 1.2", runtime: false},
    ]
  end
end

Limitations

Let me believe that Karma returns!

Developers are humans, too, we also need to pay bills from time to time. If you wish to repay time and effort that you have saved thanks to this piece of code, you can click one of this nice, shiny buttons below:

Paypal Bitcoin Beerpay
<br> 1LHsmP3odWxu1bzUfe2ydrewArB72XbN7n Go to Beerpay

Authors

Marcin Lewandowski, marcin@saepia.net

License

MIT