Minimal Phoenix and Elixir Dockerfile Example

Recently, I was setting up a Dockerfile for a Phoenix web app. There are official Elixir Docker images, but finding one specifically set up to handle the Phoenix Framework with asset compilation is messier territory. There’s no single set of “official” configurations.

Everybody has an opinion about how you should do this. A lot of these opinions involve adding a lot of bells and whistles. For one, their preferred solution might include Docker Compose. For another, Distillery releases. Since I had not successfully deployed my app with Docker yet at all, I wanted fewer variables to debug.

Here’s what I came up with:

FROM elixir:1.8.0-alpine

#### If needed for native dependencies
RUN apk add --no-cache make gcc libc-dev

ENV CC=gcc
ENV MAKE=cmake
#####

RUN mix local.hex --force \
  && mix local.rebar --force

WORKDIR /root/app

ADD ./ /root/app/

EXPOSE 4000

ENV MIX_ENV=prod
ENV PORT=4000

RUN mix deps.get
RUN mix deps.compile
RUN mix compile
RUN mix phx.digest

CMD ["mix", "phx.server"]

This starts with the elixir alpine image. Alpine is a skinny Linux that works well in containers. I’ve found that it is a suitable base for Elixir apps. In my case, I needed a C toolchain to compile some libraries. You might not need that part. Then it sets up hex and rebar for fetching and building dependencies. Then it adds the application directory. It sets the default port and environment. It fetches the dependencies, compiles them, compiles the app, and digests the assets. Then, it starts the server. That’s it.

This approach follows the minimal instructions for a production Phoenix deployment on Docker, with no extras. From there, you can add ~complexity~ more features if you would like.

Bonus: .dockerignore for Phoenix and Elixir Projects

Here’s the .dockerignore file I use:

.git
Dockerfile

# Build artifacts
_build
deps
*.ez

# Crash dumps from Erlang VM
erl_crash.dump

# NPM dependencies added by asset pipeline
node_modules
def create(conn, %{"post" => post_params}) do
    case Posts.create_posts(post_params) do
      {:ok, post} ->
        conn
        |> put_flash(:info, "Posts created successfully.")
        |> redirect(to: posts_path(conn, :show, post))
      {:error, %Ecto.Changeset{} = changeset} ->
        render(
          conn,
          "new.html",
          changeset: changeset,
          post_type: post_params["post_type"] || "post",
          author_options: User |> Repo.all()
        )
    end
  end

Categories: code


5 Factors for Well-Being. What is the PERMA model?

The PERMA model is a theoretical model of wellbeing designed by Martin Seligman as part of a branch of psychology known as “positive psychology.” I originally ran across it as part of The Science of Well-Being course that I took last year. Seligman and others designed PERMA as a simple, but scientifically-validated model for understanding well-being and happiness. People use the PERMA model in their day to day lives to think about, and improve, their well-being. It is also used in research on well-being in positive psychology.

PERMA is an acronym and each letter represents one of the components of the model:

  • Positive Emotions
  • Engagement
  • Relationships
  • Meaning
  • Achievement

Positive Emotions. Clearly, positive emotions are strongly connected to happiness. In this case, positive emotions specifically means feel joy, positivity, and contentedness.

Engagement. Engagement means how often you become absorbed in what you are doing and lose track of time. Research shows that getting into a “flow” state when working or doing a hobby leads to a feeling of satisfaction.

Relationships. Our connection to other people also drives our feeling of well-being. Our feeling that people love us and support us contributes to our feeling of well-being.

Meaning. We want to feel like the things we are doing matter and that we have a purpose.

Achievement. A feeling that we have, make progress to, and achieve our goals contributes to our sense of well-being.

Psychologists have experimentally shown that each of these five components materially correlates with well-being and happiness.

The PERMA model is also the basis for the PERMA Profiler, which assesses these factors as a numerical score. This is useful because we can use this score to quantitatively track well-being. We can do experiments to see which other techniques and factors might influence well-being.

How to calculate the PERMA Profiler score

Julie Butler and Margaret L. Kern developed the PERMA Profiler as a brief way to measure the PERMA factors and other factors in general well-being.

The PERMA Profiler is a 23 question survey. It includes 3 questions for each of the five PERMA categories (15 PERMA questions), plus 3 questions on negative emotion, 3 questions on health, 1 question on loneliness, and 1 question on general sense of well-being. We rate each question on a relevant 0 to 10 scale— for example “0 Never to 10 Always” or “ 0 Terrible to 10 Excellent.” To calculate the PERMA Profiler overall well-being score, you average the 15 PERMA questions and the general well-being question. The other seven questions disrupt answering tendencies, which makes the answers more accurate. They also record other information relevant for positive psychology researchers.

Research psychologists have been experimentally validated the PERMA Profiler measure in several different contexts. They have also compared and correlated the PERMA Profiler to a lot of other measures of well-being. If you’d like to read the original paper it is freely available here.

My Experience With PERMA and the PERMA Profiler

I’m a person who has to apply a lot of techniques to regulate my mood and my energy levels. PERMA feels like it correlates well to how I feel on any given day. This makes it useful for self-experimentation and has part of my self-evaluation of my feelings.

As I said, I first learned about PERMA through The Science of Well-Being course that I took last year. Throughout the course, I took the PERMA Profiler every week and made note of my score each time. I also made notes about my emotional and physical health at the time I took the PERMA survey. In my experience, PERMA does a fairly good job of mirroring my feelings of well-being or lack thereof. On my worst days, I’ll score a 4.5 out of 10. My best days are an eight. My most typical score is around a seven these days.

I created the PERMA profiler as a Google Form. Since the summary score is just an average of 16 of the 23 questions, it was easy to compute. This format makes it easy for me to compare the results to other factors, like how many tasks I do in Todoist or whether I checked off my habits in Habitica.

I’ve found it useful as a data point I can measure about myself and compare with other factors. Does PERMA go up when I exercise? Does it go down when I have a lot of meetings? Or alternately, am I more likely to stick to my positive habits if my PERMA score is high?

I recognize that I’ve gamified this well-being score. I realize that by knowing about how the score works, I may be influencing my results. I can’t say for sure that this attention I’m placing on the number isn’t distorting my results. I worry that I’m putting pressure on myself to increase the score, rather than well-being. But I can say that I feel better and that’s the point.

Categories: