Building Images with sealos build
The build
command in Sealos is used to build OCI images using instructions from Sealfiles, Kubefiles, Dockerfiles, or Containerfiles. This is the fundamental command in Sealos for building cluster images.
If no parameters are specified, Sealos will use the current working directory as the build context and look for instruction files. If no Sealfile, Kubefile, Dockerfile, or Containerfile is found, the build will fail.
Here are some key options for the build
command:
--all-platforms
: Attempts to build the image for all supported base image platforms.--authfile
: Path to the authentication file.--build-arg
: Provides anargument=value
to the builder.--build-context
: Provides additional build context to the builder asargument=value
.--creds
: Credentials to access the registry as[username[:password]]
.-D, --disable-compression
: Disables layer compression by default.--env
: Sets environment variables for the image.-f, --file
: Pathname or URL of the Dockerfile.--force-rm
: Always removes intermediate containers after a build, even if the build fails.--format
: Format for the manifest and metadata of the built image.--from
: Replaces the value of the first FROM instruction in the Containerfile with the specified image name.--http-proxy
: Passes the HTTP Proxy environment variable.--isolation
: Process isolationtype
to use, can be 'oci' or 'chroot'.--max-pull-procs
: Maximum number of goroutines to use for pulling images.--platform
: Sets the OS/ARCH/VARIANT for the image to the provided value instead of the host's current operating system and architecture.--pull
: Pulls the image from the registry, if new or not present in the store. Can be set to false, always, or never.-q, --quiet
: Suppresses the build output and image read/write progress.--retry
: Number of times to retry on push/pull failure.--retry-delay
: Delay in seconds between retries on push/pull failure.--rm
: Removes intermediate containers after a successful build.--save-image
: Saves resolved images from a specific directory in the registry format.--sign-by
: Signs the image with the GPG key of the specifiedFINGERPRINT
.-t, --tag
: Name and optionally a tag in the 'name:tag' format to apply to the built image.--target
: Sets the target build stage to build.--timestamp
: Sets the created timestamp to the specified epoch seconds for reproducible builds. Default is the current time.
These options provide flexibility for various build requirements, including platform-specific builds, environment variable settings, build context management, image signing, and more. With the --save-image
option, Sealos can automatically recognize and save the required images (including those resolved from image lists, Helm charts, and manifests) in the Docker Registry format.
The process isolation mode --isolation
supports two parameters: 'oci' and 'chroot'. Choose 'oci' mode if OCI is supported locally and 'chroot' mode if OCI is not supported.
The --save-image
option is used in Sealos build commands to automatically find and save the required images during the build process. In Sealos, building an image may involve other dependent images. These dependent
images can come from image lists, Helm charts, or cluster manifests. When using the --save-image
option, Sealos will automatically resolve these dependencies based on the build context and save them in the Docker Registry format.
For example, here is an example using the --save-image
option:
sealos build -t myapp:v1.0.0 -f Dockerfile .
In this example, Sealos will use the current directory as the build context, read the build instructions from the Dockerfile, and attempt to build an image tagged as myapp:v1.0.0
. Additionally, Sealos will resolve all base images referenced in the Dockerfile's FROM
instructions and save those images as well. These images will be saved in the Docker Registry format and can be pushed directly to a Docker Registry.
If your build context also includes Helm charts or cluster manifests, Sealos will also resolve the images referenced in those files and save them accordingly.
Overall, the --save-image
option provides a convenient way for Sealos to handle image dependencies during the build process, greatly improving the convenience and efficiency of building images.
Here are some detailed examples:
- Build with Image Manifests
- Build with Deploy Manifests
- Build with Helm Charts
- Build with Binary
- Build with go-template
- Build with exec and scp
With the build
command in Sealos, you can build OCI images based on various instruction files to provide the required images for Sealos. This process includes handling various instructions in Dockerfiles or other instruction files, such as FROM
, RUN
, ADD
, etc., as well as managing image layers, labels, and more. The build process also involves pulling base images, running commands, saving the results, and more. Each step can be finely controlled and customized using the options mentioned above to accommodate different build requirements.
That's the usage guide for the sealos build
command. We hope this helps you. If you have any questions or encounter any issues during the process, feel free to ask us.