Light Docker Container for Phoenix and Postgresql by

Light Docker Container for Phoenix and Postgresql

Last update: 3 years ago Tag : elixir, phoenix framework, docker, docker-compose, postgresql, apline

Sometimes ago I wrote about alpine vagrant for Rails 5, but sadly it's not working, although rails 5 successfully installed. Now, it's the time for me to try docker for phoenix development. I'm using docker-compose for orchestrating the phoenix and the postgres database server.

Here are the steps: (Actually I just followed the steps from here, but I changed the postgresql section using the alpine's version.)

  1. Create a new project using docker: docker run --rm -v $(pwd):/cwd -ti mrrooijen/phoenix mix my_project. Wait until the process finished. Enter to the newly created folder: cd my_project.
  2. Create docker-compose.yml with the following content:
        build: .
        dockerfile: Dockerfile.local
        command: mix phoenix.server
            - 4000:4000
            - .:/cwd
            - db

        image: kiasaki/alpine-postgres
  1. Create Dockerfile.local with the following content:
    FROM mrrooijen/phoenix
    RUN apk --no-cache add postgresql-client
  1. Edit config/dev.exs and config/test.exs, change localhost to db (to connect the project to the database server).
  2. Run docker-compose run web mix deps.get and create the database: docker-compose run web ecto.create.
  3. Run docker-compose up --build to build the image and run the phoenix project.
  4. As usual, open http://localhost:4000 to test the running project.
  5. For other commands, just open a new terminal and execute docker-compose run web <command> in the my_project folder.

Share this post: