I use ruby:2.7.1-alpine for my project
it installs Node version 12, I need version >=16 (I think 18 is desirable) to work with react.
how can I update the version in my Dockerfile ?
FROM ruby:2.7.1-alpine
ARG RAILS_ROOT=/task_manager
ARG PACKAGES="vim openssl-dev postgresql-dev build-base curl nodejs-current yarn less tzdata git postgresql-client bash screen gcompat"
RUN apk update
&& apk upgrade
&& apk add --update --no-cache $PACKAGES
RUN gem install bundler:2.1.4
RUN mkdir $RAILS_ROOT
WORKDIR $RAILS_ROOT
COPY Gemfile Gemfile.lock ./
RUN bundle install --jobs 5
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
ADD . $RAILS_ROOT
ENV PATH=$RAILS_ROOT/bin:${PATH}
EXPOSE 3000
CMD bundle exec rails s -b '0.0.0.0' -p 3000
currently in this build the following options are available:
bash-5.0# apk search nodejs
nodejs-12.22.12-r0
npm-12.22.12-r0
nodejs-current-doc-14.5.0-r0
nodejs-current-14.5.0-r0
nodejs-dev-12.22.12-r0
nodejs-current-dev-14.5.0-r0
nodejs-doc-12.22.12-r0
I can’t figure it out.
2
Answers
I just change FROM ruby:2.7.1-alpine to FROM ruby:3.0-alpine and build new image
I see 2 options to be somewhat independent of your original image:
Use node version management this tool helps keep multipliemanage installation of node in the system. There are some caveats using it with alpine but it is solvable. Check out their documentation.
Second option (less pretty in my opinion) is to use copy from another pre-build node alpine image, it can be done like this:
To adjust node version, just change node-XX:alpine image version, everything should continue to work (except for yarn, you’ll have to adjust its path)