Dockerize, a small package to help generating Docker images for your Elixir projects

Dockerize - A small hex package for creating Docker images from an Elixir project.

Hi, guys,

I’ve been playing with Elixir and Docker together for some time and today I’d like to share some of my experiences on running Elixir on Docker to the community. This includes:

  • Dockerize - the hex package that helps scaffolding
  • Two Docker base images: elixir-builder & elixir-runner, used by this package by default.

Also, I wrote a blog post on how to do it manually if you want to build your own stacks.

This is a tiny library and many others may have better solutions, but I think it will provide most of the developers a good start on deployment.

So, please check it if you’re going to de deployments, and don’t hesitate to drop any comment or advice. It will help me improving it definitely.



v0.2.0 updates

  • faster building speed, normally arround 3min with fresh (depending on your project) and seconds with cache
  • smaller size of the final built image, ~30MB
  • better support for Phoenix projects. Now it automatically detect if you are in a Phoenix project.

v1.0.0 released!

  • use explicit base Docker images from scratch so developers can have full control
  • use Debian instead of Alpine as the system image by default (to trade-off for better maintainability)
  • documentation improvements

Welcome to give it a try!


Can you clarify on that? I am not a heavy Docker user but I do use it and so far I’ve had no problems with Alpine.


Yes! Alpine is surely amazing. I am a fan of it too but I found that I have to deal with the differences between musl and standard libc. If the library owner uses NIF and doesn’t provide prebuilt binaries, we have to compile it ourselves. Compiling on Alphine today is a bit harder than Debian because musl is not the majority. I’m sure it will get better as Alpine becomes more and more popular.

I picked Alpine because it is super small. But today thanks to Docker layer caching and cloud building, we don’t need to build locally and push to remote, sizing is not a big problem now. making the library smoother to adapt seems more important to me.


Yep, I’ve been bitten once by libmusl when working actively with Rust last year (by the famous slower memory allocation) but I haven’t revisited in a while and I am curious if that has been fixed.

As for NIFs and prebuilt binaries I prefer them built in the container anyway but I get what you are saying! :slight_smile:

Yep, got introduced to that several months ago and I loved it. I wonder if people are updating their Docker files en masse to make use of this fantastic feature, hmmmm.

Thanks for this. Any plans on doing a write-up on Rio? I like how it will fetch and maintain Let’s Encrypt certs for you.

I was shocked by how it simplified the certification flow and image building flow when I tried Rio a year ago. It’s a good direction but by that time it was unstable. I am glad to take your suggestion and give it another try!

1 Like

Today I released version v1.1.0.


  • support building assets with esbuild in Phoenix 1.6
  • some improvements on the usage of ARG and ENV instructures.

I have a trivial hello_world phoenix 1.6 project that I’m trying to dockerize using this tool and I’m running into
#32 2.083 npm WARN npm npm does not support Node.js v10.24.0

stack after doing

mix archive.install hex dockerize
mix dockerize.init
DOCKER_BUILDKIT=1 docker build .

To try and fix this I added some lines at the beginning, but seems to not have any impact. Any ideas?

FROM hexpm/elixir:1.12.2-erlang-24.1-debian-buster-20210902 AS elixir-builder
RUN apt update && apt install -y git build-essential
+ RUN apt update
+ RUN curl -sL | bash -
+ RUN apt-get install -y nodejs
+ RUN apt install -y npm
 => ERROR [digest 2/2] RUN mix assets.deploy                                                                     3.3s 
 > [digest 2/2] RUN mix assets.deploy:                                                                                
#32 2.083 npm WARN npm npm does not support Node.js v10.24.0                                                          
#32 2.086 npm WARN npm You should probably upgrade to a newer version of node as we                                   
#32 2.087 npm WARN npm can't make any promises that npm will work with this version.                                  
#32 2.088 npm WARN npm Supported releases of Node.js are the latest release of 4, 6, 7, 8, 9.                         
#32 2.088 npm WARN npm You can find the latest version at                                         
#32 2.153                                                                                                             
#32 2.153 > @ deploy /src/assets
#32 2.153 > NODE_ENV=production tailwindcss --postcss --minify --input=css/app.css --output=../priv/static/assets/app.css
#32 2.153 
#32 3.223 /src/assets/node_modules/color/index.js:257
#32 3.223 			lum[i] = (chan <= 0.039_28) ? chan / 12.92 : ((chan + 0.055) / 1.055) ** 2.4;
#32 3.223 			                  ^^^^^
#32 3.223 
#32 3.223 SyntaxError: Invalid or unexpected token
#32 3.223     at Module._compile (internal/modules/cjs/loader.js:723:23)
#32 3.223     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
#32 3.223     at Module.load (internal/modules/cjs/loader.js:653:32)
#32 3.223     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
#32 3.223     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
#32 3.223     at Module.require (internal/modules/cjs/loader.js:692:17)
#32 3.223     at require (internal/modules/cjs/helpers.js:25:18)
#32 3.223     at Object.<anonymous> (/src/assets/node_modules/tailwindcss/lib/util/pluginUtils.js:25:37)
#32 3.223     at Module._compile (internal/modules/cjs/loader.js:778:30)
#32 3.223     at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
#32 3.239 npm ERR! code ELIFECYCLE
#32 3.239 npm ERR! errno 1
#32 3.242 npm ERR! @ deploy: `NODE_ENV=production tailwindcss --postcss --minify --input=css/app.css --output=../priv/static/assets/app.css`
#32 3.242 npm ERR! Exit status 1
#32 3.242 npm ERR! 
#32 3.242 npm ERR! Failed at the @ deploy script.
#32 3.242 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
#32 3.253 
#32 3.253 npm ERR! A complete log of this run can be found in:
#32 3.253 npm ERR!     /root/.npm/_logs/2021-12-14T18_53_00_631Z-debug.log
#32 3.274 ** (exit) 1
#32 3.274     (mix 1.12.2) lib/mix/tasks/cmd.ex:64:
#32 3.274     (mix 1.12.2) lib/mix/task.ex:394: anonymous fn/3 in Mix.Task.run_task/3
#32 3.274     (mix 1.12.2) lib/mix/task.ex:452: Mix.Task.run_alias/5
#32 3.274     (mix 1.12.2) lib/mix/cli.ex:84: Mix.CLI.run_task/2
executor failed running [/bin/sh -c mix assets.deploy]: exit code: 1

Hi Maz, could you open an issue on Github? I just tried the latest version of Phoenix (1.6.6) and it works. According to your log, I assume this is something related to the assets compiling so if you create a repo to reproduce it, it will be perfect.