53 lines
1.6 KiB
Markdown
53 lines
1.6 KiB
Markdown
|
|
# Image Support Files
|
||
|
|
|
||
|
|
This directory contains helper scripts that enable NVM (Node Version Manager) functionality in Docker images.
|
||
|
|
|
||
|
|
## Files
|
||
|
|
|
||
|
|
### bash-with-nvm
|
||
|
|
|
||
|
|
A wrapper script used as the SHELL directive in Dockerfiles. It loads NVM before executing any RUN command, enabling commands like:
|
||
|
|
|
||
|
|
```dockerfile
|
||
|
|
SHELL ["/usr/local/bin/bash-with-nvm"]
|
||
|
|
RUN nvm install 18
|
||
|
|
RUN node --version
|
||
|
|
```
|
||
|
|
|
||
|
|
### docker-entrypoint.sh
|
||
|
|
|
||
|
|
An entrypoint script that ensures NVM is available at runtime. It handles:
|
||
|
|
|
||
|
|
1. Loading NVM environment on container start
|
||
|
|
2. Special handling for `bash -c` commands (common in CI/CD) to inject bashrc sourcing
|
||
|
|
|
||
|
|
## Usage
|
||
|
|
|
||
|
|
These files are copied into Alpine-based Docker images:
|
||
|
|
|
||
|
|
```dockerfile
|
||
|
|
COPY image_support_files/bash-with-nvm /usr/local/bin/bash-with-nvm
|
||
|
|
COPY image_support_files/docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
|
||
|
|
RUN chmod +x /usr/local/bin/bash-with-nvm /usr/local/bin/docker-entrypoint.sh
|
||
|
|
|
||
|
|
SHELL ["/usr/local/bin/bash-with-nvm"]
|
||
|
|
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
|
||
|
|
```
|
||
|
|
|
||
|
|
## Why These Scripts Are Needed
|
||
|
|
|
||
|
|
NVM is a bash function, not a binary. This creates challenges in Docker:
|
||
|
|
|
||
|
|
1. **Build time**: Each RUN command starts a fresh shell without NVM loaded
|
||
|
|
2. **Runtime**: Container commands don't automatically have NVM available
|
||
|
|
3. **CI/CD**: Non-interactive shells (bash -c) need special handling
|
||
|
|
|
||
|
|
These scripts solve all three contexts.
|
||
|
|
|
||
|
|
## Maintenance
|
||
|
|
|
||
|
|
When updating NVM version, ensure compatibility with both scripts. The NVM_DIR path (`/usr/local/nvm`) must match across:
|
||
|
|
- These scripts
|
||
|
|
- Dockerfile ENV declarations
|
||
|
|
- /etc/bash.bashrc configuration
|