Use the preBuild.bash Script
Overview
The preBuild.bash script runs before packages install during the container build.
Use it to set up the environment and prepare for package installation. Commands run automatically when you rebuild the container.
The script runs as the container user with passwordless sudo access.
You can install system packages, modify permissions, and configure services. Changes persist across container restarts because they’re baked into the image.
The build context is separate from the project.
The script cannot access files in the /project/ directory during build. Install from external sources like GitHub, PyPI, or URLs instead.
Key Concepts
preBuild.bash
Optional bash script in the project root that runs before package installation. Used for environment setup and system preparation.
Build Order
Container build follows: base image —> preBuild.bash —> package installation —> postBuild.bash —> completed image.
The onStart.bash script runs later, each time a container starts from that image.
Build Context
Separate folder containing only the containerfile, package files, and build scripts. Does not include project files, so the script cannot access /project/ during build.
Passwordless Sudo
The script can run commands with sudo without password prompts. Allows system-level changes during the build.
Edit preBuild.bash in the Desktop App
Step One: Open the script editor.
- Select Project Tab > Project Container > Scripts
- Select preBuild.bash
- Select Edit Script
Step Two: Add your commands to the script.
- Type or paste your bash commands in the editor
- Select Save
Step Three: Rebuild the container to apply changes.
- Select Project Tab > Project Container > Start Build
Success: The container rebuilds with your script changes applied.
Edit preBuild.bash Directly
Step One: Open the script file in your project root.
- Open preBuild.bash in any text editor
Step Two: Add your commands to the script.
- Write bash commands in the file
- Save the file
Step Three: Rebuild the container.
- Select Project Tab > Project Container > Start Build
Success: The container rebuilds with your script changes applied.
What preBuild.bash Can and Cannot Access
The script CANNOT access the following.
- Files in the project (anything in /project/)
- Environment variables defined in variables.env
- Data files or models in your project
The script CAN access the following.
- System package managers (apt, yum, etc.)
- Python package managers (pip, conda)
- External resources (GitHub, PyPI, URLs with curl/wget)
- System directories and files being created during the build
- Build-time environment variables you set in the script itself
Common Mistakes to Avoid
Don’t try to copy files from /project/
This will fail because /project/ doesn’t exist during build:
Don’t try to pip install from local project files
This will fail because the files aren’t in the build context:
Don’t reference environment variables from variables.env
These aren’t set during the build:
Workarounds
Install from external sources instead
Download from GitHub or other external locations:
Set build-time variables in the script
Define variables you need in the build script itself:
Use Cases for preBuild.bash
Add apt repositories or signing keys before packages install.
Create directories that will be needed later.
Install tools needed for compiling packages.
Configure custom package sources or mirrors.
Fix base image issues before package installation.
Best Practices
Use set -e for error handling
Exit immediately if any command fails:
Add comments to explain complex operations
Document what your script does:
Use absolute paths for file operations
Avoid issues with working directories:
Test scripts in isolation when possible
Run commands manually in a container to verify they work before adding to scripts.
Related Topics
- Use the postBuild.bash Script - Configure the container after package installation
- Use the onStart.bash Script - Initialize the running container at each start
- Package Management - Add packages to your container
- Configure Runtime Settings - Set environment variables and mounts
- Use a Custom Container - Use your own base image