berry
berry copied to clipboard
[Bug?]: "docker compose run" with docker cache fails after building ( it can not find yarn installed module in cache folder)
Self-service
- [ ] I'd be willing to implement a fix
Describe the bug
I use this command to first build a docker image :
yarn exec "docker compose --env-file rioniz_initializer.env -f docker_compose_rioniz_initializer.yaml build"
Then I use following command to run it :
yarn exec "EXEC_COMMAND=initializeDatabase docker compose --env-file rioniz_initializer.env -f docker_compose_rioniz_initializer.yaml run --rm rioniz_initializer"
But it fails with this error ( it works fine with old yarn v1 but not now with yarn v4 , I guess sth in yarn cause docker compose run fails)
node:internal/modules/run_main:129
triggerUncaughtException(
^
Error: Required package missing from disk. If you keep your packages inside your repository then restarting the Node process may be enough. Otherwise, try to run an install first.
Missing package: tsx@npm:4.19.1
Expected package location: /root/.yarn/berry/cache/tsx-npm-4.19.1-aace436c49-10c0.zip/node_modules/tsx/
This is my dockerfile
# Use node alpine as the base image
FROM node:20-alpine
# Set the working directory to /app
WORKDIR /app
# Copy the necessary files for dependency installation
COPY package.json ./
COPY yarn.lock ./
COPY tsconfig.json ./
# Copy the source code into the container
COPY src ./src
# Enable production env for node
ENV NODE_ENV=production
# Install dependencies using Yarn 4
RUN corepack enable
RUN --mount=type=cache,target=/root/.yarn YARN_CACHE_FOLDER=/root/.yarn \
yarn --immutable
# Use a dynamic command to run the yarn initialization script defined by EXEC_COMMAND
CMD sh -c " yarn $EXEC_COMMAND"
Also this is my dependencies in package.json ( tsx is already in dependencies)
"dependencies": {
"@keycloak/keycloak-admin-client": "25.0.5",
"axios": "1.7.7",
"commander": "12.1.0",
"cron-validate": "1.4.5",
"dotenv": "16.4.5",
"dotenv-flow": "4.1.0",
"json5": "2.2.3",
"lodash": "4.17.21",
"mysql2": "3.11.2",
"node-cron": "3.0.3",
"tsx": "4.19.1",
"typescript": "5.6.2",
"yaml": "2.5.1",
"yup": "1.4.0"
},
"devDependencies": {
"@types/dotenv": "8.2.0",
"@types/jest": "29.5.11",
"@types/lodash": "4.14.199",
"@types/node": "20.11.5",
"@types/node-cron": "3.0.11",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"dotenv-cli": "7.4.2",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-jest": "28.6.0",
"nodemon": "3.1.4",
"prettier": "3.3.2",
"pretty-quick": "4.0.0"
},
To reproduce
It should be reprodusible from the bug discription but if it is necessary I can also make a repository for it and share it
Environment
System:
OS: Linux 5.15 Alpine Linux
CPU: (16) x64 AMD Ryzen 7 5800H with Radeon Graphics
Binaries:
Node: 20.17.0 - /tmp/xfs-19d7b165/node
Yarn: 4.4.1 - /tmp/xfs-19d7b165/yarn
npm: 10.8.2 - /usr/local/bin/npm
Additional context
No response