• Stars
    star
    244
  • Rank 165,885 (Top 4 %)
  • Language Makefile
  • License
    GNU General Publi...
  • Created almost 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A dockerized Phoenix development and runtime environment.

A Containerized Dev Environment for Elixir and the Phoenix Framework

Introduction

A dockerized development environment to work on Elixir and Phoenix framework projects while keeping the host environment pristine.

This project was conceived to deal with the issues of running different Elixir and Phoenix versions and supporting the development and maintenance of apps built with different Elixir and Phoenix versions.

Maybe you are working on multiple different projects, built with different versions of the Phoenix framework, or you are working on a long-lived Elixir or Phoenix project. In either case you are likely to hit a version conflict. Phoenix and Elixir are still young and evolving which is great - but some of the changes will likely break your application code. This repository aims to make things easier for you by giving you a straightforward path in swapping out your Elixir and Phoenix environment.

Notable Changes

  • #1d570c14007b7750da776e0b6bd2b7568ec67de5 We've switched the default branch of the repository from master to main. Please update your local repository refs!

  • Docker Phoenix 1.6.15 We are currently in the process of switching to Alpine Linux based images, which are significantly smaller (~150MB vs 1.7GB). Expect the next release to make -alpine the new default for the dev environments. As a result, you will need to rebuild your VSCode dev containers and your application code.

  • Docker Phoenix 1.6.13 Starting with this version, we've switched the Docker image hosted at Docker Hub (docker pull nicbet/phoenix:1.6.13) to M1 Mac, i.e., linux/arm64/v8 architecture. If you are developing on an Intel machine, you will need to build the docker image on your platform to get started run make docker-image.

Getting Started

As of December 2022, we recommend using the Visual Studio Dev Containers approach over the command line. See below for details.

Visual Studio Code (Dev Containers)

Setting up a brand-new project

If you are using a recent version of Visual Studio Code with the Dev Containers extension, we highly recommend going this route for a much improved development experience out of the box.

  1. Use Degit to quickly clone this project as a scaffold for your new project, for example an app called hello_world.

    npx degit nicbet/docker-phoenix#1.7.0 hello_world
  2. Open the hello_world folder in Visual Studio Code

  3. When asked, select Reopen in container. Visual Studio code will create a complete application stack including a PostgreSQL database, and mount your local ./app folder as the root folder for the development environment.

  4. After initialization of your dev environment finishes, open the Terminal tab in Visual Studio Code.

  5. Create your new Phoenix application with the following command (note the .!):

    mix phx.new . hello_world
  6. As the mix command runs, you will see your Visual Studio Code file explorer populate with the files of your new phoenix app. All these files are available outside your development environment in the ./app folder.

Note: You don't need to use degit. Alternatively, you can clone this repository and remove the .git folder manually.

Configuring the Database Connection

Both, the docker-compose stack started with the docker-compose.yml file included with this repository and the Visual Studio Code Dev Containers stack define a service called db for running a PostgreSQL database that is available to the main application container via the hostname db. By default Phoenix assumes that you are running a database locally. In order to use the db service with your application you will need to modify your Phoenix config and point Ecto to the database host.

To use the included database with your phoenix application you will need to modify the Ecto configuration config/dev.exs and point it to the DB container:

# Configure your database
config :test, Test.Repo,
  adapter: Ecto.Adapters.Postgres,
  hostname: "db",
  username: "postgres",
  password: "postgres",
  # ...
  pool_size: 10

Running your Application

To start you application in development mode you will first need to change your Phoenix configuration to bind the phx.server to 0.0.0.0, so that the container exposes the phx.server to the host network.

To bind the phx.server to all interfaces, edit your config/dev.exs file and set the endpoint listen address to 0.0.0.0:

config :hello_world, HelloWorldWeb.Endpoint,
  http: [ip: {0, 0, 0, 0}, port: 4000],
  ...

From the VSCode terminal you can run the Phoenix application server with:

mix phx.server

Once the startup is completed, your app will be available at http://localhost:4000

Using the Command Line instead of Dev Containers

After cloning the repository, you can use the included ./run, ./mix, ./npm, and ./yarn scripts to execute commands in the development environment described by included docker-compose.yml file. For instance, running ./mix phx.new . hello_world would generate a new phoenix application called hello_world. Similarly to the Visual Studio Code Dev Containers approach, your project files will be locally stored in the ./app container which is mounted to /app inside the development environment.

The instructions for changing the database connection and bind address as described above apply here as well.

To run any command inside the dev container, you can use the ./run script and pass the command and its arguments.

./run iex -S mix

Building the image for your platform

You can locally build the container image with the included Makefile:

make docker-image

Usage with an existing project

You can use this project to dockerize the development enviroment for an existing project. Follow the steps above, but instead of initializing a new application with mix phx.new, copy your existing project code to the ./app subdirectory. This will make your existing code available in the dockerized dev environment.

Contributing

This project is intended to be a safe, welcoming space for collaboration. Contributors are expected to adhere to the Contributor Covenant code of conduct. We recommend reading the contributing guide as well.

License

Docker Phoenix is available as open source under the terms of the GNU Public License v3.

Contributors

Docker Phoenix is built by members of the Open Source community, including:

apenney

cruisemaniac

homanchou

tmr08c

jacknoble

ravloony

asifaly

ajmeese7

restlessronin

More Repositories

1

essence

Essence is a library for Natural Language Processing and Text Summarization in Elixir.
Elixir
64
star
2

infozilla

The infoZilla unstructured software engineering data mining tool. It can find and extract source code regions, patches, stack traces, enumerations and itemizations from discussion threads.
Java
13
star
3

MailboxMiner

Tool to mine Mail Repositories in the form of MBOX archives into a PostgreSQL Database representation. Some of the perks include: robustness to different MBOX file formats, detection of message encoding and transformation into UTF8, unpacking of MIME messages, separate saving of attachments, automatic copies of HTML emails into plain text (useful for data mining), resolution of multiple identities (matches aliases by name heuristics), and many more.
Java
12
star
4

rails7-wysiwyg-editor

A WYSIWYG Editor for Markdown written in Rails 7 with Hotwired Turbo and Stimulus
Ruby
10
star
5

rails-uikit

UIKit3 for Ruby on Rails • https://getuikit.com
CSS
8
star
6

performance-testing

A curated list of awesome performance testing tools
6
star
7

ccfinderx-osx

Mac OS X port of CCFinderX
Python
2
star
8

docker-sinatra-mongoid-skeleton

A web application skeleton for a dockerized Ruby Sinatra over Puma via Foreman app, backed by MongoDB via Mongoid driver
Ruby
2
star
9

cart

Crystal Adaptive Radix Tree Implementation
Crystal
2
star
10

nerves-buildroot-docker

Buildroot Container for building customized Nerves firmware for rPi3
2
star
11

archlinux-x230

Arch Linux on Thinkpad X230
2
star
12

docker-rails5-dev-env

Dockerized, reproducible Rails 5 development environment that makes it easier to work on multiple projects at the same time and takes the guess-work out of installing local copies of ruby and rails.
Shell
1
star
13

simple-ast-diff

Semantic (AST) Diff for Java
Java
1
star
14

vscode-devcontainer-rails

Ruby on Rails Development in a Devcontainer for Visual Studio Code
Dockerfile
1
star
15

exmach

Machine Learning From Scratch in Elixir
Elixir
1
star
16

elixir_get_scrubber

Sample code to the article posted under http://nicolas-bettenburg.com/articles/scrubbing-get-params-with-phoenix/
Elixir
1
star