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.
Trending in Announcing
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixirconf-us
- #ai
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 41 to 32- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
jarlah
Aaand
there we go

Version 2.0.0, Enjoy,
jarlah
Wow, august 2025, last comment.
Lots have happened people! Testcontainers for Elixir is now in a release candidate version v2.0.0-rc2
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
Test it out
On hex here
jarlah
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:
and server or setup like before
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
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
Should probably add “aliases” like mix tc.run etc.
jarlah
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
Old task mix testcontainers.test is still working. Its redirecting to the new task.
jarlah
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
Thanks to github user kianmeng for this helpful testing.
jarlah
Big news
Testcontainers for Elixir now has (rootless) podman support
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
Try it out and see how/if it works for you.
dimitarvp
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
I have released v1.11.0 today but its mostly maintenance.
A small poll:
please add your emojis and/or comment
thanks