1
0
mirror of https://github.com/openshift/openshift-docs.git synced 2026-02-07 00:48:01 +01:00
Files
openshift-docs/modules/virt-preparing-container-disk-for-vms.adoc

49 lines
1.9 KiB
Plaintext

// Module included in the following assemblies:
//
// * virt/virtual_machines/virtual_disks/virt-using-container-disks-with-vms.adoc
[id="virt-preparing-container-disk-for-vms_{context}"]
= Preparing a container disk for virtual machines
You must build a container disk with a virtual machine image and push it to a container registry before it can used with a virtual machine. You can then either import the container disk into a PVC using a data volume and attach it to a virtual machine, or you can attach the container disk directly to a virtual machine as an ephemeral `containerDisk` volume.
.Prerequisites
* Install `podman` if it is not already installed.
* The virtual machine image must be either QCOW2 or RAW format.
.Procedure
. Create a Dockerfile to build the virtual machine image into a container image. The virtual machine image must be owned by QEMU, which has a UID of `107`, and placed in the `/disk/` directory inside the container. Permissions for the `/disk/` directory must then be set to `0440`.
+
The following example uses the Red Hat Universal Base Image (UBI) to handle these configuration changes in the first stage, and uses the minimal `scratch` image in the second stage to store the result:
+
[source,terminal]
----
$ cat > Dockerfile << EOF
FROM registry.access.redhat.com/ubi8/ubi:latest AS builder
ADD --chown=107:107 <vm_image>.qcow2 /disk/ <1>
RUN chmod 0440 /disk/*
FROM scratch
COPY --from=builder /disk/* /disk/
EOF
----
<1> Where <vm_image> is the virtual machine image in either QCOW2 or RAW format. +
To use a remote virtual machine image, replace `<vm_image>.qcow2` with the complete url for the remote image.
. Build and tag the container:
+
[source,terminal]
----
$ podman build -t <registry>/<container_disk_name>:latest .
----
. Push the container image to the registry:
+
[source,terminal]
----
$ podman push <registry>/<container_disk_name>:latest
----