Home > Mobile >  How to set node version to 16.x for ruby:3.0.1-alpine3.13 image in Dockerfile
How to set node version to 16.x for ruby:3.0.1-alpine3.13 image in Dockerfile

Time:10-04

The following is the Dockerfile I have set up for one of my applications:

FROM ruby:3.0.1-alpine3.13

ENV APP_PATH /var/app
ENV BUNDLE_VERSION 2.2.17
ENV RAILS_PORT 3000
ENV LAUNCHY_DRY_RUN true
ENV BROWSER /dev/null

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh

RUN chmod  x /usr/local/bin/docker-entrypoint.sh

# install dependencies for M1 Macs
RUN apk add --update --no-cache curl py-pip python2 python3

# install dependencies for application
RUN apk -U add --no-cache \
make \
gcc \
build-base \
git \
postgresql-dev \
postgresql-client \
libxml2-dev \
libxslt-dev \
nodejs \
npm \
yarn \
tzdata \
&& rm -rf /var/cache/apk/* \
&& mkdir -p $APP_PATH


RUN gem install bundler --version "$BUNDLE_VERSION"

# navigate to app directory
WORKDIR $APP_PATH

COPY Gemfile Gemfile.lock ./
COPY package.json yarn.lock ./

RUN bundle check || bundle install --jobs=8
RUN yarn install --check-files

COPY . .

EXPOSE $RAILS_PORT

This by default sets the node version to 14.17.4. This used to work when I had set the node engine value in package.json to 14.x, but since I have changed the node engine value to 16.x I'm getting this error when I'm trying to build a container with this Dockerfile.

I have searched and tried various approaches to set the node version in Dockerfile using nvm, n, etc, but to no avail.

Is there an easy way to set and change this node version?

Thank you

CodePudding user response:

For installing Node.js 16.x on Alpine 3.14, install the nodejs-current package:

https://pkgs.alpinelinux.org/package/v3.14/community/x86_64/nodejs-current

Simply replace nodejs with nodejs-current in your package list.
The current nodejs-current version is 16.6.0-r0.

  • Related