solie.space

 
Light Docker Container for Phoenix and Postgresql by solie.space

Light Docker Container for Phoenix and Postgresql

Last update: a year 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 phoenix.new 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:
    web: 
        build: .
        dockerfile: Dockerfile.local
        command: mix phoenix.server
    ports:
            - 4000:4000
    volumes:
            - .:/cwd
    links:
            - db

    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: