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?

Marked As Solved

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!

Also Liked

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.

iboard

iboard

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

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

Where Next?

Popular in Questions Top

marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jaysoifer
Is there a way to rollback a specific migration and only that one (“skipping” all the other ones)? Would mix ecto.rollback -v 200809061...
New
earth10
Hi, I’m just starting to build a side-project with Elixir and Phoenix and doing some basic test with Elixir alone. What strikes me is th...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

Other popular topics Top

axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 48342 226
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
AstonJ
Posting this to see if we can make things easier for people to get into Neovim. If you use Neovim and have a favourite distro please let ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
klo
Got a question about when to concat vs. prepending items to list then reversing to achieve appending. So i know lists boil down to [1 | ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

Latest on Elixir Forum

Elixir Forum

We're in Beta

About us Mission Statement