Creating a custom Docker image with a specified version of the Node package installed

My goal is to create a Docker image with a node package installed. If I hardcode the package version in the Dockerfile, everything works fine (@14.0.0):

FROM stefanscherer/node-windows:12.16.1-nanoserver-1909
RUN npm install -g @sitecore-jss/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e3908a9786808c915b8d80808dc08986191eadaf4ada7ada7">[email protected]</a>

Building command and output:

docker build -t sitecore-jss-cli:14.0.0-nanoserver-1909 .

Successfully built 1c0ebbcd5be2
Successfully tagged sitecore-jss-cli:14.0.0-nanoserver-1909

However, if I pass the version as an argument (to be able to use any version), an error occurs. Here's the updated Dockerfile:

ARG SITECOREJSS_VERSION
FROM stefanscherer/node-windows:12.16.1-nanoserver-1909
RUN npm install -g @sitecore-jss/sitecore-jss-cli@${SITECOREJSS_VERSION}

The command with the argument and resulting error message:

docker build --build-arg SITECOREJSS_VERSION=14.0.0 -t sitecore-jss-cli:14.0.0-nanoserver-1909 .

...
npm ERR! code EINVALIDTAGNAME
npm ERR! Invalid tag name "${SITECOREJSS_VERSION}": Tags may not have any characters that encodeURIComponent encodes.

It seems like the argument needs to be escaped somehow. Any suggestions on how to resolve this issue?

Answer №1

You are facing two main challenges:

  1. Ordering Issue

    The ARG variable declared outside the FROM block can only be accessed within the FROM line itself. To resolve this, if you do not need to utilize the --build-arg as part of the FROM, it should be moved inside:

    FROM stefanscherer/node-windows:12.16.1-nanoserver-1909
    ARG SITECOREJSS_VERSION
    ...
    

    If the ARG needs to be used both in the FROM statement and elsewhere in the Dockerfile, it must be explicitly stated:

    ARG SITECOREJSS_VERSION
    FROM ...
    ARG SITECOREJSS_VERSION
    ...
    
  2. Interpolation Problem

    According to this GitHub issue, when performing interpolation in commands within Windows images, you have to use %:

    RUN npm install -g @sitecore-jss/sitecore-jss-cli@%SITECOREJSS_VERSION%
    

To make it all work correctly, your updated code snippet would look like this:

FROM stefanscherer/node-windows:12.16.1-nanoserver-1909
ARG SITECOREJSS_VERSION
RUN npm install -g @sitecore-jss/sitecore-jss-cli@%SITECOREJSS_VERSION%

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Ways to showcase my Node.js CLI module across various environments

As I develop a cli using nodejs, named xygcli, everything appears to be running smoothly. However, once it was published, I received feedback from some users indicating that they were unable to locate the command "xygcli not found (zsh)" Even though they ...

Stagnation in the progress of React installation

I've tried installing npx create-react-app project and npm init react-app project multiple times, but each time the installation process gets stuck at a certain point and does not progress further. This seems to be an issue with the installation that ...

Guide to setting up npm for use with Github

Recently starting my journey with github, I am eager to delve into working with npm and node js. However, encountering errors during the installation process of npm has left me stuck. After successfully cloning my project from GitHub, the next step is to i ...

Utilizing NodeJs to establish a seamless connection with elasticsearch

Recently, I have been exploring the option of updating my REST API to utilize elasticsearch. After some research, I came across the mongoosastic plugin, which appears to be a promising solution. However, I am having difficulty establishing a connection bet ...

Node.js Reverse Geocoding with NPM

I am currently working on implementing the reverse-geocoding package. You can find more information about it at https://www.npmjs.com/package/reverse-geocoding However, I seem to be facing an issue with the documentation as it is causing the following err ...

What would occur in the event that NPM were to shut down completely?

I can't help but wonder, what would the repercussions be if NPM were to unexpectedly cease operations? With so many NodeJS projects dependent on its packages, would they all be left in a lurch? Is there even a possible recovery plan for such a scenari ...

Separating the NPM MySql connection into its own file is necessary

I need to establish a connection to a separate file using npm MySQL. My goal is to export the connection variable or pool variable every time I execute a query. The issue I'm currently facing is that the connection gets recreated each time when I sepa ...

I am encountering some difficulties in the installation process of Angular CLI

Encountering an error trying to install angular cli despite updating both node and npm. https://i.stack.imgur.com/SpkNU.jpg ...

Centralized platform for accessing node and npm installers that adhere to Nexus standards

I am searching for a nexus-compliant repository where I can find a node installer that aligns with Nexus guidelines (an alternative to http://nodejs.org/dist/). Situation : In our Java environment, Maven handles our builds. We recently integrated a JavaS ...

Error: The type definition file for webpack-env cannot be located during the build process

Our team is working on a .net core Asp.net framework Single Page Application (SPA). We recently encountered an issue while using the Nuget package manager console in Visual Studio 2017. Despite executing various commands, including npm init and npm install ...

Can webpack be used to import a bundled webpack and library separately in a project?

I am currently working on a module that utilizes d3, but I do not wish to include d3 in the bundled package or bind it to the window object. This module will be installed in another project using npm as a git dependency. In my module setup, I have configur ...

Error message appears: "Unable to access 'upgrade' property of undefined" upon launching Vue application

Everything was running smoothly with my project for a few months. I could easily execute npm run serve without any issues, even when switching networks. But now, no matter what I do, I can't seem to get the server to start again. The error message I&a ...

After being transpiled with babel-preset-es2015, what is the designated global function or namespace for ES6 modules?

Currently, I have my developer tools open and I'm trying to locate the installed modules using the console. Below are the versions listed in my package.json. You can also access the compiled bundle.js at https://pastebin.com/EbTg6bSF. "devDependencie ...

Issue with Laravel Spark due to NPM Dependencies

Trying to install Spark within Laravel on a Docker container running Debian 8, but encountering an error when running NPM update. Not sure how to resolve this issue. Installing NPM Dependencies... npm WARN deprecated <a href="/cdn-cgi/ ...

Having trouble sorting out the array in my Node.js code

In a Node.js code snippet, the task is to extract all the links from a web page and then store them in a variable within the function's scope without displaying the data outside of the function. var ineed = require('ineed'); var url = requi ...

The directory of your cache is populated with files that are owned by the

When attempting to execute npm ci on a git deployment branch for my website, I encountered the following error message: npm ERR! code EACCES npm ERR! syscall mkdir npm ERR! path /home/storm/.npm npm ERR! errno -13 npm ERR! npm ERR! Your cache folder includ ...

Setting timeouts during Vue-cli unit testing can help improve the efficiency and accuracy of your tests

I have been running vue unit tests using the following command: vue-cli-service test:unit However, I am encountering an issue where some unit tests require a response from the server, causing them to take longer to execute. Is there a way for me to man ...

Utilizing the require pattern to integrate JavaScript functionality into HTML

Have: project |- consume_script.js |- index.html Need index.html to be like: <html> <head> </head> <body> <script src="consume_script.js"></script> </body> </html> Issue: consume_script ...

The React development server is currently inaccessible due to an error: ERR_CONNECTION_REFUSED

I'm currently attempting to locally run a React application by using npm start, however, I'm encountering an issue with connecting to it through my web browsers (both Chrome and Firefox). The error message I'm receiving is ERR_CONNECTION_REF ...

What is the best way to make a service in minikube accessible from another device on the same network?

I have set up a service in minikube (expressjs API) on my local machine. When I start the service using minikube service wedeliverapi --url, I am able to access it from my browser at localhost:port/api. https://i.stack.imgur.com/Rhm3B.png https://i.stack ...