Learn to use a project.toml file for build configuration, including default builders and file exclusions in your application packaging process.
In this lesson, you will learn how to leverage a project.toml file to embed build configuration details directly into your application. This configuration file allows you to define default builders and control which files are included in your final container image, eliminating the need to specify flags (such as the builder flag) with every build command.For example, instead of executing:
you can create a project.toml file in your project’s root directory with the builder information. This file guides the buildpacks to select the correct builder by default when packaging your application.
Start by copying one of the provided examples and then modify it to suit your application. For instance, here’s how you might configure a project.toml for a Node.js application:
This snippet sets the schema version, provides a unique machine-readable ID, a human-friendly name, and version information. The [io.buildpacks] section specifies the default builder. You can override these settings when running the pack build command, if necessary.
Sometimes it is important to prevent certain files from being copied into the final container image—files like local dependencies stored in a node_modules folder, environment variables, tests, or dummy files used during development.
By excluding unnecessary files, you can streamline your image, making it leaner and more responsive.
For example, if you have a dummy file that you do not want copied into the final image, include an exclude section in your project.toml:
After saving changes to your project.toml, rebuild your image by running:
Copy
Ask AI
pack build myapp --path nodejs-app/
Then run your container:
Copy
Ask AI
docker run -d -p 8000:8080 myapp
Verify the running container with:
Copy
Ask AI
docker ps
To confirm that the excluded files have not been copied, open a shell inside the container:
Copy
Ask AI
docker exec -it <container-id> bashls
You should notice that files such as dummfile.txt are not present in the container workspace, confirming that your exclude configuration works as intended.
Alternatively, you may prefer to explicitly specify the files or directories to include in the build context. This method excludes all other files not explicitly listed. For example:
The full specification of project.toml supports various configurations such as setting environment variables for the build process or even specifying individual buildpacks. Consider the following example:
How to embed default builder configurations within a project.toml file, eliminating the need to pass the builder flag with every command.
Techniques to exclude specific files and directories from the build context, similar to using a .dockerignore file.
How to opt for an include-based configuration to precisely define which files are part of your build.
Additional configuration options available to further customize your build process.
By properly configuring your project.toml, you can optimize your build process and ensure that your final image contains only the necessary files and settings.For more details, visit the Buildpacks Documentation and other related resources.