CentOS 7
Sponsored Link

Buildah : Install2018/08/30

 
Install Buildah that supports to create Container images.
It's possible to create OCI (Open Container Initiative) format image or Docker format image without Docker Service Daemon.
[1] Install Buildah.
[root@dlp ~]#
yum -y install buildah
[2] This is the basic usage for Buildah.
Create a working container from an image.
# create from [centos] image

[root@dlp ~]#
buildah from centos

Getting image source signatures
Copying blob sha256:256b176beaff7815db2a93ee2071621ae88f451bb1e198ca73010ed5bba79b65
 71.23 MiB / 71.23 MiB  4s
Copying config sha256:5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892
 2.13 KiB / 2.13 KiB  0s
Writing manifest to image destination
Storing signatures
centos-working-container

# container list

[root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
c28ce3a30750     *     5182e96772bf docker.io/library/centos:latest  centos-working-container

# container image list

[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                            CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest       Aug 7, 2018 04:21      208 MB

# if you'd like to create empty container, specify [scratch]

[root@dlp ~]#
buildah from scratch

working-container [root@dlp ~]#
buildah containers

CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME                       CONTAINER NAME
c28ce3a30750     *     5182e96772bf docker.io/library/centos:latest  centos-working-container
df3709dc7552     *                  scratch                          working-container

# [scratch] is empty, so not listed on image list

[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                             CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest        Aug 7, 2018 04:21      208 MB
[3] Operate working container.
# set shell variable

[root@dlp ~]#
container=$(buildah from centos)

[root@dlp ~]#
echo $container

centos-working-container-2
# possible to run commands

[root@dlp ~]#
buildah run $container echo "Hello Buildah"

Hello Buildah
[root@dlp ~]#
buildah run $container bash

[root@mrsdalloway /]#
yum install ruby

[root@mrsdalloway /]#
[root@dlp ~]#
buildah run $container whereis ruby

ruby: /usr/bin/ruby /usr/lib64/ruby /usr/share/ruby
[4] Copy content into working container.
[root@dlp ~]#
echo "buildah test" > buildah.txt

[root@dlp ~]#
buildah copy $container buildah.txt /tmp/buildah.txt

ce9440fee6e37151fcc872dbf3fca2a77b95e66a627cabed14ba8349e1825607
[root@dlp ~]#
buildah run $container cat /tmp/buildah.txt

buildah test
[5] Edit settings of working container.
[root@dlp ~]#
buildah config --hostname my-hostname $container

[root@dlp ~]#
buildah run $container hostname

my-hostname
# show current settings

[root@dlp ~]#
buildah inspect $container

{
    "Type": "buildah 0.0.1",
    "FromImage": "docker.io/library/centos:latest",
    "FromImageID": "5182e96772bf11f4b912658e265dfe0db8bd314475443b6434ea708784192892",
.....
.....
        "config": {
            "Hostname": "my-hostname",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
.....
.....

# other options for [buildah config]

[root@dlp ~]#
buildah config -h

NAME:
   buildah config - Update image configuration settings

USAGE:
   buildah config [command options] CONTAINER-NAME-OR-ID

DESCRIPTION:
   Modifies the configuration values which will be saved to the image

OPTIONS:
   --annotation annotation, -a annotation   add annotation e.g. annotation=value, for the target image (default [])
   --arch architecture                      set architecture of the target image
   --author information                     set image author contact information
   --cmd command                            set the default command to run for containers based on the image
   --comment comment                        set a comment in the target image
   --created-by description                 set description of how the image was created
   --domainname name                        set a domain name for containers based on image
   --entrypoint entry point                 set entry point for containers based on image
   --env environment variable, -e .....     add environment variable to be set when running containers based on image (default [])
   --history-comment comment                set a comment for the history of the target image
   --hostname name                          set a hostname for containers based on image
   --label label, -l label                  add image configuration label e.g. label=value
   --onbuild value                          add onbuild command to be run on images based on this image. Only supported on 'docker' formatted images
   --os operating system                    set operating system of the target image
   --port port, -p port                     add port to expose when running containers based on image (default [])
   --shell shell                            add shell to run in containers
   --stop-signal stop signal                set stop signal for containers based on image
   --user user, -u user                     set default user to run inside containers based on image
   --volume volume, -v volume               add default volume path to be created for containers based on image (default [])
   --workingdir directory                   set working directory for containers based on image
[6] Mount filesystem of working container.
[root@dlp ~]#
buildah mount $container

/var/lib/containers/storage/overlay/58c70666c54601d8ce6c96c6079ed45ca60af25ff97cadc77cdfe2c937081b25/merged
[root@dlp ~]#
ll /var/lib/containers/storage/overlay/58c70666c54601d8ce6c96c6079ed45ca60af25ff97cadc77cdfe2c937081b25/merged

total 16
-rw-r--r--.  1 root root 12005 Aug  5 07:05 anaconda-post.log
lrwxrwxrwx.  1 root root     7 Aug  5 07:04 bin -> usr/bin
drwxr-xr-x.  2 root root     6 Aug  5 07:04 dev
drwxr-xr-x. 47 root root  4096 Aug  5 07:05 etc
drwxr-xr-x.  2 root root     6 Apr 11 13:59 home
.....
.....

# unmount

[root@dlp ~]#
buildah umount $container

cb2fdccb666dcfd76ce526021db07652d87702bb245c711ef28ff5b34ed5588e
[7] Create a container image from working container.
[root@dlp ~]#
buildah commit $container my-centos:latest

Getting image source signatures
Skipping fetch of repeat blob sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a
Copying blob sha256:4f4fb700ef54461cfa02571ae0db9a0dc1e0cdb5577484a6d75e68dc38e8acc1
 32 B / 32 B  0s
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 1.18 KiB / 1.18 KiB  0s
Writing manifest to image destination
Storing signatures
4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                             CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest        Aug 7, 2018 04:21      208 MB
4b5dfca9b616         localhost/my-centos:latest             Aug 28, 2018 19:13     208 MB
[8] Push a container image to specified location.
[root@dlp ~]#
buildah images

IMAGE ID             IMAGE NAME                               CREATED AT             SIZE
5182e96772bf         docker.io/library/centos:latest          Aug 7, 2018 04:21      208 MB
4b5dfca9b616         localhost/my-centos:latest               Aug 28, 2018 17:13     208 MB

# push [localhost/my-centos] image to [www.srv.world:5000] registry

[root@dlp ~]#
buildah push localhost/my-centos www.srv.world:5000/my-centos

Getting image source signatures
Copying blob sha256:1d31b5806ba40b5f67bde96f18a181668348934a44c9253b420d5f04cfb4e37a
 198.64 MiB / 198.64 MiB  19s
Copying blob sha256:5f70bf18a086007016e948b04aed3b82103a36bea41755b6cddfaf10ace3c6ef
 1.00 KiB / 1.00 KiB  0s
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 1.18 KiB / 1.18 KiB  0s
Writing manifest to image destination
Copying config sha256:4b5dfca9b6165627a7328eef35db5216f28c5c0504e05c2bb8d3e98a1d2382a3
 0 B / 1.18 KiB  0s
Writing manifest to image destination
Storing signatures

# possible to Pull on other Docker Nodes

[root@www ~]#
docker pull www.srv.world:5000/my-centos

[root@www ~]#
docker images

REPOSITORY                     TAG         IMAGE ID         CREATED          SIZE
www.srv.world:5000/my-centos   latest      4b5dfca9b616     40 hours ago     200 MB
docker.io/centos               latest      5182e96772bf     3 weeks ago      200 MB
docker.io/registry             2           b2b03e9146e1     7 weeks ago      33.3 MB
Matched Content