Git Product home page Git Product logo

phoenix-docker-example's Introduction

Webexample

This is an example of packaging and running a Phoenix application with docker.

Quick start:

$ make
$ docker run -p 8001:8001 webexample

Overview

The build process works as follows:

  • clone this repo to docker/webexample
  • build a docker image named webexample using docker/ as the context

Caveat: there is currently one unresolved problem with getting mix dependecies to build as part of the image build process. If you are getting build errors, run MIX_ENV=prod mix deps.compile once inside docker/webexample on your host machine.

If you are running docker inside a VM, you may need to perform a few additional steps manually. One of them is adding a port forwarding rule in the VM settings to map a port from the VM to the host OS.

Note that it is OK to hardcode the port number used inside the image the way we did. When you run the image, you can map the container port to any other available port on the host (or the VM in the case when docker itself is running in a VM).

Points of interest

Elixir dependencies

The current setup fetches dependencies before building the docker image to speed up the rebuild process. Depending on how you are planning to use docker, you might want to include that as part of the image build or, alternatively, add a rule to the Makefile that will run mix deps.update --all after pulling the latest changes with git.

Iterative development

An important thing to understand about this example: it demoes how one would package an Elixir app in a docker image for deployment. This works fine if you don't need to rebuild the image too often. This workflow differs in a number of ways from using docker as part of the development process.

For the latter case you will have to come up with ways to make docker automatically pick up the latest version of your project's code and update any other environment settings in the presences of code changes. You could mount the directory with your project code as a host volume in the running docker container (passing the -v option to docker run). That implies building the project either when the container starts or beforehand.

Alternative build strategies

With docker it is possible to create "builder images". Those are images that produce build artifacts when run. You could create such an image for your project to have the compilation and running phases separate but still using the same environment and Elixir versions (enforced via a single base image). This workflow is not explored in the present demo.

phoenix-docker-example's People

Contributors

alco avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.