Generate app image from source code
Pack Build uses Cloud Native Buildpacks to create a runnable app image from source code.
Pack Build requires an image name, which will be generated from the source code. Build defaults to the current directory, but you can use --path
to specify another source code directory. Build requires a builder
, which can either be provided directly to build using --builder
, or can be set using the set-default-builder
command. For more on how to use pack build
, see: https://buildpacks.io/docs/app-developer-guide/build-an-app/.
pack build <image-name> [flags]
pack build test_img --path apps/test-app --builder cnbs/sample-builder:bionic
-B, --builder string Builder image (default "cnbs/sample-builder:noble")
-b, --buildpack strings Buildpack to use. One of:
a buildpack by id and version in the form of '<buildpack>@<version>',
path to a buildpack directory (not supported on Windows),
path/URL to a buildpack .tar or .tgz file, or
a packaged buildpack image name in the form of '<hostname>/<repo>[:<tag>]'
Repeat for each buildpack in order, or supply once by comma-separated list
-r, --buildpack-registry string Buildpack Registry by name
--cache cache Cache options used to define cache techniques for build process.
- Cache as bind: 'type=<build/launch>;format=bind;source=<path to directory>'
- Cache as image (requires --publish): 'type=<build/launch>;format=image;name=<registry image name>'
- Cache as volume: 'type=<build/launch>;format=volume;[name=<volume name>]'
- If no name is provided, a random name will be generated.
(default type=build;format=volume;type=launch;format=volume;)
--cache-image string Cache build layers in remote registry. Requires --publish
--clear-cache Clear image's associated cache before building
--creation-time string Desired create time in the output image config. Accepted values are Unix timestamps (e.g., '1641013200'), or 'now'. Platform API version must be at least 0.9 to use this feature.
-D, --default-process string Set the default process type. (default "web")
-d, --descriptor string Path to the project descriptor file
--docker-host string Address to docker daemon that will be exposed to the build container.
If not set (or set to empty string) the standard socket location will be used.
Special value 'inherit' may be used in which case DOCKER_HOST environment variable will be used.
This option may set DOCKER_HOST environment variable for the build container if needed.
-e, --env stringArray Build-time environment variable, in the form 'VAR=VALUE' or 'VAR'.
When using latter value-less form, value will be taken from current
environment at the time this command is executed.
This flag may be specified multiple times and will override
individual values defined by --env-file.
Repeat for each env in order (comma-separated lists not accepted)
NOTE: These are NOT available at image runtime.
--env-file stringArray Build-time environment variables file
One variable per line, of the form 'VAR=VALUE' or 'VAR'
When using latter value-less form, value will be taken from current
environment at the time this command is executed
NOTE: These are NOT available at image runtime."
--extension strings Extension to use. One of:
an extension by id and version in the form of '<extension>@<version>',
path to an extension directory (not supported on Windows),
path/URL to an extension .tar or .tgz file, or
a packaged extension image name in the form of '<hostname>/<repo>[:<tag>]'
Repeat for each extension in order, or supply once by comma-separated list
--gid int Override GID of user's group in the stack's build and run images. The provided value must be a positive number
-h, --help Help for 'build'
--interactive Launch a terminal UI to depict the build process
--lifecycle-image string Custom lifecycle image to use for analysis, restore, and export when builder is untrusted.
--network string Connect detect and build containers to network
-p, --path string Path to app dir or zip-formatted file (defaults to current working directory)
--platform string Platform to build on (e.g., "linux/amd64").
--post-buildpack stringArray Buildpacks to append to the groups in the builder's order
--pre-buildpack stringArray Buildpacks to prepend to the groups in the builder's order
--previous-image string Set previous image to a particular tag reference, digest reference, or (when performing a daemon build) image ID
--publish Publish the application image directly to the container registry specified in <image-name>, instead of the daemon. The run image must also reside in the registry.
--pull-policy string Pull policy to use. Accepted values are always, never, and if-not-present. (default "always")
--report-output-dir string Path to export build report.toml.
Omitting the flag yield no report file.
--run-image string Run image (defaults to default stack's run image)
--sbom-output-dir string Path to export SBoM contents.
Omitting the flag will yield no SBoM content.
--sparse Use this flag to avoid saving on disk the run-image layers when the application image is exported to OCI layout format
-t, --tag strings Additional tags to push the output image to.
Tags should be in the format 'image:tag' or 'repository/image:tag'.
Repeat for each tag in order, or supply once by comma-separated list
--trust-builder Trust the provided builder.
All lifecycle phases will be run in a single container.
For more on trusted builders, and when to trust or untrust a builder, check out our docs here: https://buildpacks.io/docs/tools/pack/concepts/trusted_builders
--trust-extra-buildpacks Trust buildpacks that are provided in addition to the buildpacks on the builder
--uid int Override UID of user in the stack's build and run images. The provided value must be a positive number
--volume stringArray Mount host volume into the build container, in the form '<host path>:<target path>[:<options>]'.
- 'host path': Name of the volume or absolute directory path to mount.
- 'target path': The path where the file or directory is available in the container.
- 'options' (default "ro"): An optional comma separated list of mount options.
- "ro", volume contents are read-only.
- "rw", volume contents are readable and writeable.
- "volume-opt=<key>=<value>", can be specified more than once, takes a key-value pair consisting of the option name and its value.
Repeat for each volume in order (comma-separated lists not accepted)
--workspace string Location at which to mount the app dir in the build image
--force-color Force color output
--no-color Disable color output
-q, --quiet Show less output
--timestamps Enable timestamps in output
-v, --verbose Show more output