Home

Awesome

Dockerize is an Elixir package that helps you create Docker images from Elixir projects.

Motivation

This package is a workout of my blog post: Build Docker Images From An Elixir Project, Why and How. Of course one can write his/her own Dockerfile and play with mix release and other stuff. However, although it is fun to me, not everyone likes this job or wants to do the same setup over and over again. So I created this project and try to make a template of my Docker-related files. I hope this package will be helpful to you too.

Prerequirements

Install

mix archive.install hex dockerize

Getting Started

1. Generate configurations from template

Run this command in your project directory:

mix dockerize.init

2. Build your Docker image

just run docker build, for example

DOCKER_BUILDKIT=1 docker build .

Done!

Now you are free to do anything with the docker image built, either run it locally or host it on your infrastructures, e.g a Kubernetes cluster.

For more information on docker build, please refer to the official document.

Customizing

Full command arguments

Phoenix projects without assets

By default, it speculates if it's running in a phoenix project or not, by information from Mix.Project.config(). So basically you have to do nothing special. But if your phoenix project doesn't have assets, you could use the --no-phoenix-assets parameter on generating the Dockerfile.

Use different app name other than directory name

By default, it speculates app_name from the directory name. You can change it by:

mix dockerize.init --app my_app

use MIX_ENV other than prod

By default, it builds the image with MIX_ENV=prod. You can change MIX_ENV value by providing it as a build argument:

docker build --build-arg mix_env=dev .

use HEX_MIRROR other than the default (https://repo.hex.pm)

In some cases, you may want to use some hex mirror, with the following command:

docker build --build-arg hex_mirror_url=https://hexpm.upyun.com .

License

MIT