Solved: Mix test: could not find executable `psql` in path (using docker-compose)

** (RuntimeError) could not find executable psql in path, please guarantee it is available before running ecto commands
(ecto) lib/ecto/adapters/postgres.ex:106: Ecto.Adapters.Postgres.run_with_psql/2
(ecto) lib/ecto/adapters/postgres.ex:83: Ecto.Adapters.Postgres.storage_up/1
(ecto) lib/mix/tasks/ecto.create.ex:34: anonymous fn/2 in Mix.Tasks.Ecto.Create.run/1
(elixir) lib/enum.ex:604: Enum."-each/2-lists^foreach/1-0-"/2
(elixir) lib/enum.ex:604: Enum.each/2
test/test_helper.exs:3: (file)

I have two containers running via docker-compose; one with postgres, one with the application. I can iex -S mix phoenix.server succesfull (I have a connection to postgres then) from the same directory where mix test fails. Maybe the cause is that psql is not in the PATH (which is /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin) of my application container? The database is running in another container, I use docker-compose Here is my yml: https://github.com/StefanHoutzager/elixir-dev-anywhere-docker/blob/master/docker-compose.yml
If it could be an incomplete PATH, should I set it via the ENTRYPOINT (the script that is called from what you can configure in the Dockerfile?) of the applicationcontainer? How?

3 Likes

I do have a toy project around in which I do install the package postgresql-client on the container running phoenix.

The relevant parts of my corresponding Dockerfile:

FROM elixir:latest

RUN apt-get update && apt-get install -y postgresql-client

The compose file looks like this (again, it is stripped):

version: '2'
services:
  db:
    image: postgres
    ports: […]
    environment: […]
  web:
    build: .
    working_dir: /code
    command: […] # compile elm, run migrations and fire up phoenix
    volumes:
      - .:/code
    ports: […]
    depends_on:
      - db  

compose.yml as well as Dockerfile and the project-root are all living in the same folder.

7 Likes

Schönen Dank Norbert! Adding postgresql-client solved the problem. After that I had to add the hostname (docker servicename in docker-compose.yml) to test.exs also:
** (Mix) The database for Rumbl.Repo couldn’t be created, reason given: psql: could not connect to server: Connection refused is the server running on host “localhost” (::1)

2 Likes