How to start Phoenix by using PostgeSQL through container?

I’m tried:

$ alias psql="docker exec -ti pg-hello-phoenix sh -c 'exec psql -h localhost -p 5432 -U postgres'"
$ mix ecto.create

but got:

  • docker: possible to create a single file with binaries and packages installed?
  • docker: Error response from daemon: grpc: the connection is unavailable
  • Private Docker Registry Not Connectible to Shell & Web Management UI?
  • AWS Elastic Beanstalk Application and Static Assets Deployment Isolation
  • Kubelet image GC for docker “Data Space Total” instead of disk space
  • How to achieve cpu-throttling in docker swarm mode: docker service create
  • ** (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
    (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


    $ which 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

  • Kubernetes: Docker pod starting fails except one
  • Docker swarm and ec2, how to advertise external ip address
  • Does docker on Windows SBS 2011 write to mounted volume immediately?
  • Why the docker keeps both image and image container on VM?
  • Build docker image from rhel6.5 image
  • php application and docker share single environment file
  • 2 Solutions collect form web for “How to start Phoenix by using PostgeSQL through container?”

    To me I did the following:

    sudo docker exec -it postgres-db bash

    After I got the interactive shell

    psql -h localhost -p 5432 -U postgres

    Then I create my db manually:

    CREATE DATABASE cars_dev;

    Then finally:

    mix ecto.migrate

    Everything worked fine after that 🙂 hope it helps.

    I was able to do this by going into /config/.exs In my case it was development, so /config/dev.exs and left the hostname as localhost but added another setting for port: 32768 because that’s the port that docker exposed.

    Make sure to put a space between the port: and the number (not string). Otherwise it won’t work.

    Worked as usual after that. The natural assumption is that the username / password matches on the container as well.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.