-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix: Docker build failure - Unable to locate package nodejs #409
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
The NodeSource setup script adds the repository but doesn't refresh the apt cache, causing 'apt-get install nodejs' to fail with 'Unable to locate package'. Changes: - Add apt-get update after NodeSource setup script to refresh package lists - Combine NodeSource setup and nodejs install into single RUN for efficiency - Add apt-get clean and remove apt lists to reduce image size Fixes thoughtworks#333
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR fixes a Docker build failure where the Node.js package installation was failing with "Unable to locate package nodejs". The issue occurred because the NodeSource repository setup and package installation were in separate RUN commands, causing the package index to be unavailable in subsequent layers.
Changes:
- Combined NodeSource setup, apt-get update, and Node.js installation into a single RUN command
- Added apt cache cleanup to the Cypress dependencies installation for smaller image size
- Improved comments for clarity and added context about the installation steps
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| # Install Node.js using NodeSource - run apt-get update after setup script | ||
| # The setup script adds the NodeSource repository but apt cache may be stale | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | ||
| && apt-get update \ | ||
| && apt-get install -y nodejs | ||
|
|
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The apt-get update command here is redundant. The NodeSource setup script (setup_18.x) already runs apt-get update as part of its execution. This adds unnecessary time to the Docker build. Consider removing this line to optimize the build process.
| # Install Node.js using NodeSource - run apt-get update after setup script | |
| # The setup script adds the NodeSource repository but apt cache may be stale | |
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | |
| && apt-get update \ | |
| && apt-get install -y nodejs | |
| # Install Node.js using NodeSource | |
| # The setup script adds the NodeSource repository and runs apt-get update | |
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | |
| && apt-get install -y nodejs |
| # The setup script adds the NodeSource repository but apt cache may be stale | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ | ||
| && apt-get update \ | ||
| && apt-get install -y nodejs |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the other package installation command (lines 13-17) and Docker best practices, consider adding apt-get clean and rm -rf /var/lib/apt/lists/* at the end of this RUN command to reduce the image layer size. This helps minimize the final Docker image size by removing the apt package cache.
| && apt-get install -y nodejs | |
| && apt-get install -y nodejs \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* |
| FROM nginx:1.23.0 | ||
|
|
||
| # Update apt and install required packages | ||
| RUN apt-get update && apt-get upgrade -y |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following Docker best practices and for consistency with lines 16-17, consider adding apt-get clean and rm -rf /var/lib/apt/lists/* at the end of this RUN command to reduce the image layer size. This helps minimize the final Docker image size by removing the apt package cache after upgrades.
| RUN apt-get update && apt-get upgrade -y | |
| RUN apt-get update && apt-get upgrade -y \ | |
| && apt-get clean \ | |
| && rm -rf /var/lib/apt/lists/* |
| RUN apt-get install -y nodejs | ||
| # Install Node.js using NodeSource - run apt-get update after setup script | ||
| # The setup script adds the NodeSource repository but apt cache may be stale | ||
| RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - \ |
Copilot
AI
Jan 30, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - line downloads and executes a remote script as root without any integrity verification, creating a supply chain risk if the NodeSource endpoint or its delivery path is compromised. An attacker who can tamper with that script (via DNS, CDN, or repository compromise) could inject arbitrary commands into your build and produce a malicious image. Prefer installing Node.js via signed distribution packages or ensure the script is pinned and verified via checksum or signature before execution.
Issue
Fixes #333
Problem
Docker build fails with:
\
E: Unable to locate package nodejs
\\
This happens because the NodeSource repository setup and the \�pt-get install nodejs\ are in separate RUN commands. The package index from the first RUN layer is not available in subsequent layers.
Solution
Combined the NodeSource setup, apt-get update, and apt-get install nodejs into a single RUN command:
\\dockerfile
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - &&
apt-get update &&
apt-get install -y nodejs
\\
Root Cause
Docker layers are independent. When you run \�pt-get update\ in one layer and \�pt-get install\ in another, the package cache from the first layer is not guaranteed to be available or valid in the second layer.
Testing
This fix follows standard Docker best practices for package installation.