0

My host is Debian, and I'd like to start a new LiveView project where I don't already have any code or mix.exs.

I can't run mix phx.new from the host because Phoenix won't install w/o more up to date versions of Elixir than Debian stable ships with, and I'm trying to avoid reaching beyond what the distro offers and inviting pinning and dependency headaches down the road.

So I'd just like that to be done in the docker container, where more up to date versions of Elixir and all else can comfortably run w/o interfering with my host's setup.

Unfortunately all guides I can find online simply presume that you have Phoenix available to run from the host, and/or that you're importing (or more commonly mounting) an already existing project into the docker image.

I have also tried consulting ChatGPT for more flexible interrogative discussion of the problem, and it appears to get stuck at the same place I do: it constantly offers advice that assumes that mix phx.new was run from the host, so I get errors like Note no mix.exs was found in the current directory.

The closest-to-working config I've got going thus far includes: Dockerfile:

FROM elixir:1.14

WORKDIR /app

# No idea if manually installing Node is actually required or not in newest LiveView versions?
#RUN curl -sL https://deb.nodesource.com/setup_20.x | bash - \
#    && apt-get install -y nodejs

RUN mix local.hex --force \
    && mix local.rebar --force \
    && mix archive.install hex phx_new --force


EXPOSE 4000

ENTRYPOINT ["mix"]

RUN mix phx.new ${APPNAME} --live

WORKDIR /app/${APPNAME}

RUN mix deps.get

CMD mix phx.server

docker-compose.yml:

services:
  phoenix:
    build:
      context: .
      dockerfile: Dockerfile
    image: ${APPNAME}
    ports:
      - "4000:4000"
    volumes:
      - .:/app

Bear in mind I am redacting my actual app name and putting ${APPNAME} only for the purposes of this question; I'm not expecting the computer to parse that for any reason lol.

Also I've no need for ecto or backend database yet at this point. That may come some time down the road, my current experimental projects will be able to get along just fine with only per-session state however. :)

I've tried building Dockerfile and docker-compose.yml based on advice from various sources online, and I've tried consulting ChatGPT (both 3.5 and 4) but all approaches appear to presume that phoenix project and it's mix.exs already exists on the host before you start.

  • I wonder if [using a version manager](https://elixir-lang.org/install.html#compiling-with-version-managers) like `asdf` might be an easier way to go here? – David Maze May 15 '23 at 19:35
  • Well the advantages of dockerizing the setup include: 1. later when I want a postgresql database, I can just use the same method to keep that maintained at a constant version in lockstep with all the other software related to this project 2. That much easier to move the entire shebang to a new host – HappMacDonald May 16 '23 at 15:25

0 Answers0