jarlah

jarlah

Testcontainers

Testcontainers is an Elixir library that supports ExUnit tests, providing lightweight, throwaway instances of common databases, or anything else that can run in a Docker container.

It supports Testcontainers Desktop, but doesn’t need it to run. It will find and pick up a docker engine that works every time it runs.

Let me show you its features

In its basic form Testcontainers can used like this:

{:ok, _} = Testcontainers.start_link()
config = %Testcontainers.Container{image: "redis:latest"}
{:ok, container} = Testcontainers.start_container(config)

But the most interesting usage for Elixir is the Ecto module, which lets you run tests without having a postgres (or mysql) container running (see the README section for this advanced usage).

You can also spin up a throwaway container in a single ExUnit test:

container(:redis, Testcontainers.RedisContainer.new())

or shared container for multiple tests

container(:redis, Testcontainers.RedisContainer.new(), shared: true)

How it works

It has a dependency on an autogenerated elixir library for the docker engine api. The complex logic for calling out to docker is hidden inside that library.

Showing Posts 41 to 32

jarlah

jarlah OP

Aaand :drum: there we go :rocket: :bus:

Version 2.0.0, Enjoy,

jarlah

jarlah OP

Wow, august 2025, last comment.

Lots have happened people! Testcontainers for Elixir is now in a release candidate version v2.0.0-rc2:rocket:

Meaning: no more flaky ryuk connection on startup of tests, ability to run tests fully offline with TESTCONTAINERS_PULL_POLICY=never (or in property file in home folder) and general improvements regarding cleanup.

Im psyched about it. Specifically because i have two apps in production that i very often use claude to pair program with and when claude has to retry because flaky ryuk connection or just .. gives up running tests ? nope, doesnt cut it.

So i really hope more of you Elixir devs will find it useful now. It still doesnt support docker in docker, but thats next on the agenda :wink:

Test it out :roasted_sweet_potato:

On hex here

jarlah

jarlah OP

New release v1.13.1 completely rewrites the mix task, going from System.cmd to Mix.Task.run. I have no idea why i didn’t make it like this when i first started out.

Now you can run tests like this:

MIX_ENV=test mix testcontainers.run test

and server or setup like before

mix testcontainers.run setup --db-volume localdev
mix testcontainers.run phx.server --db-volume localdev

I decided to throw semver out of the bus for this release, so if youre using the watch option, you should look into something else, implementing the watch functionality in some other way.

jarlah

jarlah OP

Found a bug btw, that led me down a rabbit hole to refactor the whole mix task setup to programmatically run tasks, not via System.cmd, which in turn solves so many other problems. So there will come a new version soon.

jarlah

jarlah OP

Should probably add “aliases” like mix tc.run etc.

jarlah

jarlah OP

New release v1.13.0 of Testcontainers for Elixir brings real power to the library. I was very annoyed by not having the option to run my phoenix server without first starting a postgres container manually which is always a chore of keeping in sync with the migrations …

So now we can do stuff like

mix testcontainers.run setup --db-volume localdev
mix testcontainers.run phx.server --db-volume localdev

Old task mix testcontainers.test is still working. Its redirecting to the new task.

jarlah

jarlah OP

a friendly and helpful github user that previously reported podman not working, got back to me and told me that it was still not working after the release. Well i brought in the big guns, virtualbox, and installed ubuntu 24 and podman and started podman.socket service in user mode. Confirmed the issue, fixed the bug and released v1.11.5 :slight_smile: Thanks to github user kianmeng for this helpful testing.

jarlah

jarlah OP

Big news :rocket: Testcontainers for Elixir now has (rootless) podman support :muscle: :rocket: Read more here

I have had this nugget of a problem on my desk for quite some time now and its quite funny how easy it was to fix. The major problem was that I am not using podman myself. So had to test at work where they are using podman. And i have also added a github workflow to verify that everything works for both normal docker and podman.

Im very psyched about this because it opens for many more (security oriented) developers to start using the library :slight_smile:

Try it out and see how/if it works for you.

dimitarvp

dimitarvp

:thinking:

I considered it several times but I am currently on a job search so not exactly very active.

Don’t give up, I am sure people are using your library with success.

jarlah

jarlah OP

I have released v1.11.0 today but its mostly maintenance.

A small poll:

  • Are you using testcontainers for elixir (:+1:)
  • have you considered using it (:thinking:)
  • do you have problems using it (:bomb:)
  • wtf is this library (:-1: )

please add your emojis and/or comment :slight_smile:

thanks

Where Next? Top

Trending in Announcing Top

woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
fuelen
Hi all! I want to present a small library which provides a mix task for generating an Entity-Relationship Diagram for Ecto schemas. You...
New
anuaralfetahe
Hello Published a new library - ProcessHub! ProcessHub is a library designed to manage process distribution within the Elixir cluster. ...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
AstonJ
This showed up on my feed.. anyone heard of it? Just hype? Ox Alpha is a reasoning model designed for coding, sustained ag...
New
sergio
It’s not that it’s vocabulary is too advanced. It’s something worse. I get lost trying to follow even a paragraph written by Claude. It’...
New
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
sorenone
Today we’re releasing Oban for Python. Not an Oban client in Python. Not a pythonx wrapper embedded in Elixir. Nope, it’s a fully operati...
New
akoutmos
@hugobarauna, Dr. Dimitrios Koutmos (my brother) and I (Alex Koutmos) have been hard at work on writing a book on how you can use Elixir ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews