martins

martins

Mix test runs locally, but not in Docker container

Hi,

I’m able to run my test from my terminal, but if I’m not able to run the tests from within a container.

I get this error when I run docker compose up:

test-1  | Compiling 50 files (.ex)
test-1  | Generated easy_solutions app
test-1  | ** (exit) exited in: GenServer.call(ExUnit.Server, :modules_loaded, :infinity)
test-1  |     ** (EXIT) no process: the process is not alive or there's no process currently associated with the given name, possibly because its application isn't started
test-1  |     (elixir 1.14.0) lib/gen_server.ex:1027: GenServer.call/3
test-1  |     (ex_unit 1.14.0) lib/ex_unit.ex:376: ExUnit.run/1
test-1  |     (mix 1.14.0) lib/mix/compilers/test.ex:42: Mix.Compilers.Test.require_and_run/4
test-1  |     (mix 1.14.0) lib/mix/tasks/test.ex:543: Mix.Tasks.Test.do_run/3
test-1  |     (mix 1.14.0) lib/mix/task.ex:421: anonymous fn/3 in Mix.Task.run_task/4
test-1  |     (mix 1.14.0) lib/mix/task.ex:475: Mix.Task.run_alias/6
test-1  |     (mix 1.14.0) lib/mix/cli.ex:84: Mix.CLI.run_task/2

I have also tried to replace entrypoint with sleep, so that I can do a docker compose exec test /bin/bash into the container. I can confirm that mix compile works, and I get the same error when I run mix test.

Any suggestions to how I can debug this further?

test.Dockerfile

FROM ubuntu:24.04 

ENV MIX_ENV=test
ENV DOCKER_BUILDKIT=1


USER root
RUN apt update
RUN apt install -y erlang-dev elixir erlang-xmerl  
RUN apt install -y curl git 

RUN useradd -ms /bin/bash appuser
RUN mkdir /app
RUN chown -R appuser /app

USER appuser

COPY . /app
WORKDIR /app


RUN mix local.hex --force
RUN mix local.rebar --force

# install dependencies
COPY mix.exs mix.lock ./
RUN mix deps.get

# compile dependencies
COPY config ./config/


ENTRYPOINT ["mix", "test"]

docker-compose.yaml

version: "3"

services:
  test:
    environment:
      DATABASE_PATH: priv/databases/test.db
      SECRET_KEY_BASE: "l7sdfjkhj"
  

    build:
      context: .
      dockerfile:
        test.Dockerfile
    volumes:
      - ./test_result:/app/test_result


Most Liked

D4no0

D4no0

Is there a reason you are not using a pre-built docker image for that?

You can find them on dockerhub and hex.

They have erlang and elixir pre-installed and you can select the specific version you need.

martins

martins

Thanks for the suggestion, @jarlah!
Following your advice, I used the Dockerfile generated by mix phx.gen.release --docker.
I added this the the bottom of the Dockerfile:

FROM builder as test
WORKDIR "/app"

ENV MIX_ENV="test"
COPY . .

# install mix dependencies
RUN mix deps.get --only $MIX_ENV
CMD ["mix", "test"]

My docker-compose.yaml looks like this:


version: "3"

services:
  test:
    environment:
      DATABASE_PATH: priv/databases/test.db
      SECRET_KEY_BASE: "l7sdfjkhj"

    build:
      context: .
      dockerfile: Dockerfile

Now I can run my tests in a CI/CD pipeline by simply executing
docker compose up test

Where Next?

Popular in Questions Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
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
New
quazar
How to set Jason to encode all fields in ecto schema, I don’t care about security and implementing only is taking long list of attributes...
New
sacepums
Hey guys. I'm new to elixir and im really stocked about it. But I ran into a bit of problem - I need to convert a date sting, for examp...
New
vac
Hi, I'm quite new in Elixir and I'm trying to format a string to a PEM format. I have the certificate value like MIIDBTCCAe2...... and ...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New

Other popular topics Top

SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
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
pmjoe
I have a relationship of love and hate with Elixir. Lots of things are just absolutely right, but there are some things that are kind of ...
New
New
Jim
As a follow up to my earlier question: I have the code compiling and running but not getting a successful login from the rest server. ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fireproofsocks
Forgive me if this is obvious, but how does one delete a database record WITHOUT selecting it first? https://hexdocs.pm/ecto/Ecto.Repo.h...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New

We're in Beta

About us Mission Statement