Dockerizing Phoenix Development (1) Introduction
Tags: docker, elixir, phoenix, postgres
Published: 2021-05-30 18:45:22


The overall objective here is to construct a development environment within [Docker](https://www.docker.com) for a website based on: [Phoenix](https://www.phoenixframework.org/) and [Elixir](https://elixir-lang.org/) backed by [PostgreSQL](https://www.postgresql.org/) with [PostGIS](https://www.postgis.net/).

The plan is to have the Elixir and Phoenix work entirely within the container, even allowing projects to be started from scratch;  thereby removing the need to have Elixir and Phoenix installed on the host machine.

The intention here is that these steps will get a relative newcomer up and running: with some understanding. It is written to be relatively gentle on the reader, if a bit slow for some.

> For those not yet familiar: [PostGIS](https://www.postgis.net/) is a group of extensions for [PostgreSQL](https://www.postgresql.org/) which include geographical capabilities that are both sophisticated and  [standards compliant](https://www.ogc.org/) .

## Approach

Using Docker so that the project:
- can be reproduced on demand for colleagues or others.
- is largely prepared for deployment through Docker.
- can co-exist with other projects using different version permutations.

Choosing/ constructing Docker images so that they are lean and targetted to the purpose in hand.

To enable IDEs and other tools (on the host machine) to work with source code inside a container.

Using **'docker-compose'** so that parameters are scripted in the YAML format for clarity and simplicity.

## Prerequisites and Platforms

This exercise was constructed and tested on the following platform:
- [Ubuntu 20.04 LTS](https://ubuntu.com/#download) with  [Docker](https://docs.docker.com/engine/installation) and  [Docker Compose](https://docs.docker.com/engine/install/linux-postinstall/).

* There are a couple of ways of installing **docker** on Ubuntu; the recommended one is [documented on the Docker website](https://docs.docker.com/engine/install/ubuntu/)

* Reproducing this exercise should work just fine on Linux and Mac platforms. *Windows however, would be tricky for reasons explained in step 2*.

## Recommended Extras

- It is good to have a graphical view into what is going on  within the docker server.  Installing [Portainer Community Edition](https://www.portainer.io) as a container is a good option, allowing interaction through a browser.

- Given that a database is involved it is also good to have  a GUI based SQL tool on hand.  [BeeKeeper Studio](https://www.beekeeperstudio.io/) is one option (also available among the snap applications on Ubuntu).

## Remarks

* _This overall exercise reflects lessons learned the hard way by the author - a journey that took time.  This route works; however there may be better techniques - it is humbly requested that such wisdom is shared constructively in the comments._

* _You are expected to use this as a kind of template.  Use your own project acronym, use later editions of PostgreSQL, PostGIS, Elixir and/ or Phoenix; as you need._

* _If you don't need PostGIS: you can either leave it in or figure out which parts to adjust as you go through._