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

Hal9000
Here is my first stab at this. README pasted below. https://github.com/Hal9000/elixir_random Comments and critiques are welcome. Thank...
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
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
mbuhot
Leverage Open Api 3.0 (Swagger) to document, test, validate and explore your Plug and Phoenix APIs. Generate and serve a JSON Open API ...
New
josevalim
EDIT: since Ecto 3.0 final version is out, this post was amended to use the final versions in the instructions below. Hi everyone, We a...
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
384 13736 119
New
markmark206
simple_feature_flags is a tiny package that lets you turn features on or off based on which environment (e.g. localhost, staging, product...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
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 records...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
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
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 39297 209
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New

We're in Beta

About us Mission Statement