EleMenk

EleMenk

Using Docker to container Phoenix does not persist the dependencies

Hi, I am new to Phoenix and currently trying to get Phoenix into a Docker container.

Somehow, the mix deps.get and mix deps.compile commands used in the Dockerfile are executing, but the results seem not to be persisted, as I am getting this when I use the resulting Image with docker-compose:

-> % docker-compose up                    
Starting api_db_1 ... done
Starting api_web_1 ... 
Starting api_adminer_1 ... done
Attaching to api_db_1, api_web_1, api_adminer_1
db_1       | 2018-01-16 18:09:01.510 UTC [1] LOG:  listening on IPv4 address "0.0.0.0", port 5432
db_1       | 2018-01-16 18:09:01.510 UTC [1] LOG:  listening on IPv6 address "::", port 5432
db_1       | 2018-01-16 18:09:01.519 UTC [1] LOG:  listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
db_1       | 2018-01-16 18:09:01.536 UTC [23] LOG:  database system was shut down at 2018-01-16 18:05:59 UTC
db_1       | 2018-01-16 18:09:01.542 UTC [1] LOG:  database system is ready to accept connections
adminer_1  | PHP 7.2.1 Development Server started at Tue Jan 16 18:09:02 2018
web_1      | Unchecked dependencies for environment dev:
web_1      | * phoenix_live_reload (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * gettext (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * cowboy (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * phoenix_html (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * phoenix_pubsub (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * phoenix (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * postgrex (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | * phoenix_ecto (Hex package)
web_1      |   the dependency is not available, run "mix deps.get"
web_1      | ** (Mix) Can't continue due to errors on dependencies
api_web_1 exited with code 1

When running docker run --rm -it api_web /bin/bash to explore the container, the deps container is also missing in the project directory.

When I execute mix deps.get outside of the container and pass the deps into it per docker-volume it works just fine and the deps directory unsurprisingly appears.

I am taking this docker-image as a base-image: alpine-elixir-phoenix/Dockerfile at master · bitwalker/alpine-elixir-phoenix · GitHub

From there, I do this in my own Dockerfile:

FROM bitwalker/alpine-elixir-phoenix:latest
ENV MIX_ENV=dev
ADD src/mix.exs src/mix.lock ./

RUN mix deps.get
RUN mix do deps.compile, compile, phx.digest
ADD ./src .

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

finally, the docker-compose file:

db:
  image: "postgres:latest"
  ports:
    - "5432:5432"
  environment:
    POSTGRES_DB: "api_dev"
    POSTGRES_USER: "postgres"
    POSTGRES_PASSWORD: "postgres"
# phoenix web
web:
  build: "."
  volumes:
    - ./src:/opt/app
  ports:
    - "4000:4000"
  links:
     - "db:db"
  environment:
      MIX_ENV: "dev"
# adminer
adminer:
  image: adminer
  restart: always
  ports:
    - "84:8080"
  links:
     - "db:db"

Has somebody experienced similar problems?
Should I rethink putting the dependencies into the container?

First 5 of 5 Posts Switch mode

iboard

iboard

I have created a docker image in order to deploy my Phoenix app to AWS. Maybe my documentation can help.

NobbZ

NobbZ

This deletes all older content in ., so your downloaded and compiled deps are now deleted.

Better way is to do that line before deps.get and having _build in dockerignore.

EleMenk

EleMenk

ADD ./src . is actually fine, if you use ADD ./src/mix.exs ./src/mix.lock ./ before.

Anyways, you brought me on the right track! My problem were the

  volumes:
    - ./src:/opt/app

lines in the docker-compose.yml file. The Dockerfile was fine, but the dependencies got deleted everytime I brought the container up with docker-compose. Now I only have to find a way to be able to edit the code outside of the container, without deleting my dependencies.

Thank you very much for pointing me in the right direction!

iboard

iboard

The link above doesn’t work anymore. Here is the link to the old page https://blog.altendorfer.at/2017/elixir/dev/andi/2017/12/24/deploying-elixirphoenixectopostgres-project-at.html

kieraneglin

kieraneglin

— All posts loaded —

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement