ericlathrop

ericlathrop

Dockerize_elixir - quickly setup a docker dev environment in your project

When I spin up a new project, I always want a dev environment with a database and test runner. I’ve had a set of files I’ve copied from project to project over the years, but it’s manual and error prone. I’ve finally gotten annoyed enough to create a mix task that sets it all up for you.

You install it with mix archive.install hex dockerize_elixir then you can run mix dockerize path/to/my_app to install all the docker stuff into your project. Then a docker compose up will start the whole thing.

It creates 3 containers:

  1. your app
  2. postgres
  3. your tests (mix test or mix test.watch, if installed)

Things it does for you:

  1. It configures ecto to connect to the postgres container instead of localhost.
  2. It exposes port 4000 to your host machine, which is the default port for Phoenix. It also configures Phoenix to listen on 0.0.0.0, so you can actually access it.
  3. It makes a volume to share the code between your host machine and the containers.
  4. It makes volumes to isolate _build and deps folders from your host machine.

It also installs a few helper scripts:

  1. bin/iex runs iex inside the app container
  2. bin/psql runs psql inside the postgres container
  3. bin/rollback rolls back the migration. A migrate script is not necessary because it runs migrations when the container starts.

This should work for Phoenix apps, or vanilla elixir apps that use ecto.

Please give it a try and let me know how it works for you.

Most Liked

omattman

omattman

Just wanted to say thank you, @ericlathrop, for this guide. It helped me immensely, since I refuse to test anything without a basic Docker environment. Much appreciated!

Where Next?

Popular in Announcing Top

Qqwy
Hello everyone, I wrote a small library today called MapDiff. It returns a map listing the (smallest amount of) changes to get from map...
New
OvermindDL1
I created a new library (rather I pulled out a couple files from my big project), it manages an operating system PID file for the BEAM. ...
New
kelvinst
Hey everyone! Well, we made this lib a while ago and now we decided to finally go out and public with it! It’s a tool for creating and m...
New
wfgilman
I’ve cleaned up and open sourced three financial libraries I was using for my company. They are bindings for the APIs of these three comp...
New
josevalim
Hi everyone, We would like to announce that Plataformatec is working on a new MySQL driver called MyXQL. Our goal is to eventually integ...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New

Other popular topics Top

grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New

We're in Beta

About us Mission Statement