0

I have a NextJS app, that I deploy to fleek. There it gets built and deployed. I recently changed something which requires a newer node version (version 18)

The deployment used node-16 and therefore ran into an error:

enter image description here

I tried to change to node version to 18 in the fleek deploy settings page:

enter image description here

This results in an error that it can not find the docker image:

enter image description here

I then found out you can specify it like this and will give the latest node version:

fleek/next-js

This then gives me the same error as initially, so it seems this also uses version 16. Is there a way to use node 18 here and get this running?

1 Answer 1

0

To update your Dockerfile to use a specific version of Node.js (version 20.13.1 in this case), you can follow these steps. Below is the improved Dockerfile:

# Use the base image for Next.js applications
FROM fleek/next-js:latest

# Remove any existing Node.js and npm binaries
RUN rm -rf /usr/local/bin/node\
           /usr/local/bin/nodejs\
           /usr/local/bin/npm

# Define the Node.js version to be installed
ENV NODE_VERSION=20.13.1

# Download and extract Node.js
RUN wget https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-x64.tar.xz &&\
    tar -xJf node-v$NODE_VERSION-linux-x64.tar.xz &&\
    mv node-v$NODE_VERSION-linux-x64/bin/* /usr/local/bin/ &&\
    rm -rf node-v$NODE_VERSION-linux-x64 node-v$NODE_VERSION-linux-x64.tar.xz

# Verify the Node.js installation
RUN node -v

# Set the entrypoint script
ENTRYPOINT ["docker-entrypoint.sh"]

# Default command to run Node.js
CMD ["node"]

Explanation:

  1. Remove Existing Node.js and npm Binaries: Ensures any pre-installed versions are removed.
  2. Set Node.js Version: Uses an environment variable for easy version updates.
  3. Download and Install Node.js: Combines download, extraction, installation, and cleanup into a single RUN command to optimize the image.
  4. Verify Installation: Checks the installed Node.js version.
  5. EntryPoint and CMD: Sets the entrypoint script and default command.

This approach helps keep your Docker image clean, optimized, and ensures you're using the desired version of Node.js.

Happy fleeking :)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.