Este conteúdo não está disponível no idioma selecionado.
Chapter 13. Pushing a container to a registry and embedding it into an image
With RHEL image builder, you can build security-hardened images by using the OpenSCAP tool. You can take advantage of the support for container customization in the blueprints to create a container and embed it directly into the image you create.
13.1. Customizing a blueprint to embed a container into an image Copiar o linkLink copiado para a área de transferência!
Embed a container from registry.access.redhat.com by adding a container customization to your blueprint. RHEL image builder pulls the container during the image build and stores the container in the image.
The default local container storage location depends on the image type, so that all supported container-tools, such as Podman, can work with it.
Prerequisites
- You have created a blueprint.
Procedure
- Customize your blueprint with the container:
[[containers]]
source = "registry.access.redhat.com/ubi10/ubi:latest"
name = "_<local_name>_"
tls-verify = true
-
source- Mandatory field. It is a reference to the container image at a registry. This example uses theregistry.access.redhat.comregistry. You can specify a tag version. The default tag version is thelatest. -
name- The name of the container in the local registry. tls-verify- Boolean field. Thetls-verifyboolean field controls the transport layer security. The default value istrue.To access protected container resources, you can use a
containers-auth.jsonfile.
13.2. Pushing a container artifact directly to a container registry Copiar o linkLink copiado para a área de transferência!
You can push container artifacts directly to a container registry after you build them by using the RHEL image builder CLI.
Prerequisites
-
Access to quay.io registry. This example uses the
quay.iocontainer registry as a target registry, but you can use a container registry of your choice.
Procedure
Set up a
registry-config.tomlfile to select the container provider. The credentials are optional.provider = "<container_provider>" [settings] tls_verify = false username = "<admin>" password = "<your_password>"Create a blueprint in the
.tomlformat. This is a blueprint for the container in which you install annginxpackage into the blueprint.name = "simple-container" description = "Simple RHEL container" version = "0.0.1" [[packages]] name = "nginx" version = "*"Build the container image, by passing the registry and the repository to the
image-buildertool as arguments.# image-builder build --blueprint <simple-container> --extra-repo "quay.io:8080/<namespace>/<repository>" --extra-repo registry-config.tomlNoteBuilding the container image takes time because of resolving dependencies of the customized packages.
- After the image build finishes, the container you created is available in quay.io.
Verification
Open quay.io and click
Repository Tags. You can see details about the container you created, such as:- Last modified
- Image size
-
The
manifest IDthat you can copy to the clipboard.
-
Copy the
manifest IDvalue to build the image in which you want to embed a container.
13.3. Building an image and pulling the container into the image Copiar o linkLink copiado para a área de transferência!
After you create a container image, build your customized image and pull the container image into it. Use the container customization specification in the blueprint and the container name for the final image. It fetches the container image and add it to the local Podman container storage.
Prerequisites
-
You created a container image and pushed it into your local
quay.iocontainer registry instance. See Pushing a container artifact directly to a container registry. - You have access to registry.access.redhat.com.
-
You have a container
manifest ID. -
You have the
qemu-kvmandqemu-imgpackages installed.
Procedure
Create a blueprint to build a
qcow2image. The blueprint must contain the[[containers]]customization.name = "image" description = "A qcow2 image with a container" version = "0.0.1" distro = "rhel-10" [[packages]] name = "podman" version = "*" [[containers]] source = "registry.access.redhat.com/ubi10:8080/image/container/container-image@sha256:manifest-ID-from-Repository-tag: tag-version" name = "source" tls-verify = trueBuild the container image:
# image-builder build qcow2 --blueprint <blueprint>NoteBuilding the image takes time because it checks the container on
quay.ioregistry.You can use the
qcow2image you created and downloaded to create a VM.
Verification
-
Locate the resulting
qcow2image. -
Start the
qcow2image in a VM. See Creating a virtual machine from a KVM guest image. -
The
qemuwizard opens. Log in to theqcow2image by entering the username and password. These can be the username and password you set up in the.qcow2blueprint in thecustomizations.usersection, or created at boot time withcloud-init. Run the container image and open a shell prompt inside the container:
# podman run -it registry.access.redhat.com/ubi10:8080/<organization>/<repository>/bin/bash/registry.access.redhat.comis the target registry,<organization>is the organization, andrepositoryis the location to push the container when it finishes building.Check that the packages you added to the blueprint are available:
# type -a nginxThe output shows you the
nginxpackage path.