Buildah : Install2020/05/11 |
Install Buildah that supports to create Container images.
It's possible to create OCI (Open Container Initiative) format image without specific Service Daemon.
|
|
[1] | Install Buildah. |
[root@dlp ~]# dnf -y install buildah
|
[2] | This is the basic usage for Buildah. Create a working container from an image. |
# create a working container from [fedora] image [root@dlp ~]# buildah from fedora Getting image source signatures Copying blob 3088721d7dbf0.0b / 0.0b Copying config d81c91deec done Writing manifest to image destination Storing signatures fedora-working-container # show container list [root@dlp ~]# buildah containers CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME 3b142346cd14 * d81c91deec0d registry.fedoraproject.org/fe... fedora-working-container # show container image list [root@dlp ~]# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE registry.fedoraproject.org/fedora latest d81c91deec0d 11 days ago 208 MB # possible to use images on podman [root@dlp ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE registry.fedoraproject.org/fedora latest d81c91deec0d 11 days ago 208 MB |
[3] | Operate Working Container. |
# set shell variable [root@dlp ~]# container=$(buildah from fedora) [root@dlp ~]# echo $container fedora-working-container-1 # possible to run commands [root@dlp ~]# buildah run $container echo "Hello Buildah World" Hello Buildah World [root@dlp ~]# buildah run $container bash [root@0ffef2df688f /]# dnf install python3 [root@0ffef2df688f /]# [root@dlp ~]# buildah run $container whereis python3 python3: /usr/bin/python3 /usr/bin/python3.8 /usr/lib/python3.8 /usr/lib64/python3.8 /usr/include/python3.8 |
[4] | Copy files into Working Container. |
[root@dlp ~]# echo "buildah test" > buildah.txt [root@dlp ~]# buildah copy $container buildah.txt /tmp/buildah.txt c1172b94183d8ad1541c3d96e54e11a21c6b8508a0ead5d8b902b2e035ba6372[root@dlp ~]# buildah run $container cat /tmp/buildah.txt buildah test |
[5] | Mount filesystem of Working Container. |
[root@dlp ~]# buildah mount $container /var/lib/containers/storage/overlay/525ee63daa36f2b9d04d4e21ec16091c91c0ccad1f87fa2bfb1583afd70abd48/merged[root@dlp ~]# ll /var/lib/containers/storage/overlay/525ee63daa36f2b9d04d4e21ec16091c91c0ccad1f87fa2bfb1583afd70abd48/merged total 0 lrwxrwxrwx. 1 root root 7 Jan 28 13:30 bin -> usr/bin dr-xr-xr-x. 2 root root 6 Jan 28 13:30 boot drwxr-xr-x. 2 root root 6 Apr 29 02:47 dev drwxr-xr-x. 1 root root 38 Apr 29 02:47 etc drwxr-xr-x. 2 root root 6 Jan 28 13:30 home ..... ..... # unmount [root@dlp ~]# buildah umount $container 0ffef2df688fb628c7fcfaf61a0f8962f2a44abf82112ff413b51f5b9d788b2c |
[6] | Create a container image from Working Container. |
[root@dlp ~]# buildah commit $container my-fedora:latest Getting image source signatures Copying blob a4c0fa2b217d skipped: already exists Copying blob c5baae57ea51 done Copying config c3e6a732a5 done Writing manifest to image destination Storing signatures c3e6a732a5c5577d6999b3b564c3d0811f09601afd998f78298ae721d8d12908[root@dlp ~]# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/my-fedora latest c3e6a732a5c5 21 seconds ago 392 MB registry.fedoraproject.org/fedora latest d81c91deec0d 11 days ago 208 MB # possible tp use container images on podman [root@dlp ~]# podman run localhost/my-fedora echo my fedora my fedora |
[7] | Push a container image to specified Registry. |
[root@dlp ~]# buildah images REPOSITORY TAG IMAGE ID CREATED SIZE localhost/my-fedora latest c3e6a732a5c5 48 seconds ago 392 MB registry.fedoraproject.org/fedora latest d81c91deec0d 11 days ago 208 MB # push [localhost/my-centos] image to [node01.srv.world:5000] registry # if target registry is not on SSL/TLS, need [--tls-verify=false] option [root@dlp ~]# buildah push --tls-verify=false localhost/my-fedora node01.srv.world:5000/my-fedora Getting image source signatures Copying blob c5baae57ea51 done Copying blob a4c0fa2b217d done Copying config c3e6a732a5 done Writing manifest to image destination Storing signatures
[root@dlp ~]#
curl node01.srv.world:5000/v2/_catalog {"repositories":["my-fedora","nginx_server"]} # possible to Pull from other nodes [root@node01 ~]# podman pull --tls-verify=false node01.srv.world:5000/my-fedora [root@node01 ~]# podman images REPOSITORY TAG IMAGE ID CREATED SIZE node01.srv.world:5000/my-fedora latest 0a3ba69587a4 19 minutes ago 263 MB docker.io/library/registry 2 708bc6af7e5e 3 months ago 26.3 MB |
Sponsored Link |
|