Inside my docker container, the environment variable for my yarn version seems to be completely off. I am using Yarn 2, configured in the package.json. It works well, but I was confused when I stumbled over the ENV value.
What is the reason and might it have any side-effects?
package.json
{
"name": "my-project",
"type": "module",
"scripts": {
"watch": "node --watch src/app.js",
"start": "node src/app.js",
},
"packageManager": "[email protected]"
}
Dockerfile:
FROM node:21.6-alpine3.19
ENV NODE_ENV=production
RUN corepack enable
USER node
WORKDIR /home/node/app
COPY --chown=node:node . .
RUN yarn install --immutable
CMD ["yarn", "start"]
checking the actual version:
~/app $ yarn -v
4.0.2
checking the env:
~/app $ echo $YARN_VERSION
1.22.19
The reason for this discrepancy is that the
YARN_VERSIONenvironment variable is defined in the base image.In your derived image you install another version of
yarn. If you want then environment variable to be consistent then you can update it.Dockerfileentrypoint.shwhich will updateYARN_VERSION.package.jsonas supplied in original question.src/app.jsa little script with a greeting and the value ofYARN_VERSION.