Sharing CircleCI configuration / Dockerfile to build, test, and push Elixir Docker images

I spent quite a bit of time trying to find a good configuration to build / test my Elixir app in CircleCI and then push an image to Docker Hub. It is probably a somewhat common thing, but I did a lot of research and trial and error moving around different steps until I got it to a good point. I wanted to share in case in ended up being useful to somebody else searching Google :grin:


  • Uses Circle CI caching for dependencies / compiled files
  • Runs tests + code checks (using ex_check)
  • Builds and pushes images to Docker Hub:
    • One tag with the Circle CI build number
    • One tag with the git sha
    • One tag with latest (if the current branch is main)
  • A Dockerfile is included which uses Docker’s multi-stage builds and Elixir releases so that the resulting images (for this simple app) ends up around 12.5 MB

I’ve made it available in a GitHub Gist:

Comments welcome here or there


Thank you for sharing this! I’ll be trying it in the future.

Have you considered making other images not based on Alpine btw? I might try your Dockerfile with Ubuntu 20.04 which is one of the smaller images.

Yeah, absolutely try it with something else. I just used alpine because that’s what the example that I started from used :grin:

One note: at first I had alpine for the first stage but didn’t use it for the second stage and there were problems that I didn’t understand until I had done some searching around. So whatever you choose, I think you need to make sure both steps are using the same base linux distro