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 Libraries Top

scohen
Lexical Lexical is a next-generation language server for the Elixir programming language. Features Context aware code completion As-you...
New
mhanberg
I just released the first version of Temple: an HTML DSL for Elixir and Phoenix! You can read this blog post or the docs for more info...
New
deadtrickster
I’ve just released stable versions of my Prometheus Elixir libs: Elixir client [docs]; Ecto collector [docs]; Plugs instrumenter/Export...
New
riverrun
I’ve just released version 3 of Comeonin, a password hashing library. The following small changes have been made: changes to the NIF c...
New
benlime
I created a new library GitHub - benvp/ex_cva: Class Variance Authority for Elixir which aims to make it very easy to define different va...
New
benlime
LiveMotion enables high performance animations declared on the server and run on the client. As a follow up to my previous thread A libr...
New
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
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
bryanjos
Hi, I wanted share a small library we at Revelry Labs made for rendering react components from the server side. There are instructions fo...
New
mischov
import Meeseeks.CSS html = HTTPoison.get!("https://news.ycombinator.com/").body for story <- Meeseeks.all(html, css("tr.athing")) do...
New

Other popular topics Top

JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

Sub Categories:

We're in Beta

About us Mission Statement