I tried:
$ alias psql="docker exec -ti pg-hello-phoenix sh -c 'exec psql -h localhost -p 5432 -U postgres'"
$ mix ecto.create
but got:
** (RuntimeError) could not find executable
psql
in path, please guarantee it is available before running ecto commands lib/ecto/adapters/postgres.ex:106: Ecto.Adapters.Postgres.run_with_psql/2 lib/ecto/adapters/postgres.ex:83: Ecto.Adapters.Postgres.storage_up/1 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 (mix) lib/mix/cli.ex:58: Mix.CLI.run_task/2 (elixir) lib/code.ex:363: Code.require_file/2
Also I tried to create symlink /usr/local/bin/psql
:
#!/usr/bin/env bash
docker exec -ti pg-hello-phoenix sh -c "exec psql -h localhost -p 5432 -U postgres $@"
and then:
$ sudo chmod +x /usr/local/bin/psql
check:
$ which psql
/usr/local/bin/psql
$ psql --version
psql (PostgreSQL) 9.5.1
run again:
$ mix ecto.create
** (Mix) The database for HelloPhoenix.Repo couldn't be created, reason given: cannot enable tty mode on non tty input
.
Container with PostgreSQL is launched:
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
013464d7227e postgres "/docker-entrypoint.s" 47 minutes ago Up 47 minutes 5432/tcp pg-hello-phoenix