How do you specify Node/npm versions for an elixir project?

I’m new to Docker, so very 101-level advice is encouraged.

I have a Phoenix app that needs node version 14 for the assets to build successfully, and I’ve tried installing it via adding installation commands to the Dockerfile and I’ve tried this solution and I haven’t been able to get anywhere with either. Any advice on getting the node version to be what I need it to be is appreciated.

What docker base image are you using? Like if you are following the hello_elixir guide’s Dockerfile, it uses Debian Linux as the base. It’s important to know the base Linux distribution being used because they have different package managers. It also helps so you know what Google search terms to use.

But, you may just be able to do this: How to Install Node.JS 14 LTS / 16 & NPM on Debian 11 Bullseye - LinuxCapable

In your Dockerfile, in the build image portion, you might do something like this:

RUN curl -fsSL | bash -

Other Linux versions may have ready-to-go packages.

Hope that helps move you along further!

1 Like

Thanks! I’ve managed to get it working by just running npm install -g npm to get the npm version more up to date. A lot of the curl install commands don’t seem to take, which I’m guessing might be a PATH issue, but I’m not sure.

Is there a standard way with docker to be able to pause the build and get a console into the container at the pause point so you can look around and check environment variables and installations and stuff?

Yes! Just comment out the rest of the commands. So if you want to test up to a specific point, comment out the rest and build it. It makes it easier if you tag it with a name though. Like this…

docker build -t my_tag:latest .

Then you can start the container and explore what’s going on inside.

docker run -it --rm my_tag /bin/bash

This runs the container using an -it interactive terminal. It --rm removes the image after closing. The my_tag is the tag name you chose. The /bin/bash overrides the command to execute and starts a bash terminal. Depending on the base image type you are using, you may or may not have bash installed. You can also try /bin/ash which uses the Ash terminal that is common in Alpine distros.

1 Like

Brilliant; thank you!

I’ve followed the hello_elixir guide, and have subsequently added Tailwind + AlpineJS which alter the build step, but my builds now fail with

E: Unable to locate package nodejs
E: Unable to locate package npm

EDIT: I found the Elixir Getting Started Guide thread (specifically the posts from andrewbarr) which solved my issue :slight_smile:

1 Like