自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

聊聊構(gòu)建鏡像開源工具 Buildah

開源
Buildah 和Podman[9]都是互補的開源項目和命令行工具,使用并構(gòu)建 OCI 鏡像和容器。首先創(chuàng)建了 Buildah,Podman 使用與 Buildah 相同的代碼進行構(gòu)建。

1. 簡介

Buildah[1] 是一種基于 Linux 的開源工具,用于構(gòu)建與開放容器倡議 (OCI) 兼容的容器[2],這意味著容器也與Docker[3]和Kubernetes[4]兼容。借助 Buildah,您可以使用自己喜歡的工具從現(xiàn)有基礎(chǔ)鏡像或使用空鏡像從頭開始創(chuàng)建高效的容器鏡像。這是一種更靈活、更安全的構(gòu)建容器鏡像的方式。

Buildah由 Daniel Walsh 和他在 Red Hat 的團隊于 2017 年創(chuàng)建。他們著手創(chuàng)建容器鏡像的“coreutils”——一種可以與現(xiàn)有容器主機工具一起使用來構(gòu)建 OCI 和 Docker 兼容容器鏡像的工具。然后,這些鏡像可以存儲在容器倉庫[5]中,并在多個運行時環(huán)境[6]中使用。

2. 特點

  • 使用或不使用Dockerfiles[7](包含用戶可以調(diào)用以組裝鏡像的所有命令的文本文檔)構(gòu)建容器鏡像
  • 從頭開始或從現(xiàn)有容器鏡像起點創(chuàng)建容器鏡像;
  • 不在鏡像本身中包含構(gòu)建工具,減少構(gòu)建鏡像的大小,提高安全性,并允許使用更少的資源更容易地傳輸 ;
  • 與Dockerfiles 兼容,允許從 Docker 輕松轉(zhuǎn)換;
  • 創(chuàng)建特定于用戶的鏡像,以便鏡像可以按創(chuàng)建它們的用戶進行排序;
  • 檢查、驗證和修改鏡像;
  • 將容器和鏡像從本地存儲推送到公共或私有倉庫或存儲庫;
  • 從Docker Hub[8] 推送或拉取鏡像;
  • 移除本地存儲的容器鏡像;
  • 掛載和卸載工作容器的根文件系統(tǒng);
  • 使用容器根文件系統(tǒng)的更新內(nèi)容作為新鏡像的文件系統(tǒng)層。

3. Buildah 和 Podman

Buildah 和Podman[9]都是互補的開源項目和命令行工具,使用并構(gòu)建 OCI 鏡像和容器。首先創(chuàng)建了 Buildah,Podman 使用與 Buildah 相同的代碼進行構(gòu)建。但是,Buildah 的命令比 Podman 的命令詳細得多,允許對鏡像進行更細粒度的控制并允許創(chuàng)建更精細的鏡像層。Podman 的“構(gòu)建”命令使用了 Buildah 功能的一個子集。

Buildah 專注于構(gòu)建容器鏡像,復制在沒有守護程序套接字組件的 Dockerfile 中找到的所有命令,而 Podman 專注于維護和修改容器中的這些鏡像所需的東西。使用 Podman,您可以創(chuàng)建一個容器——使用 Buildah 提供容器鏡像——然后使用熟悉的命令行界面 (CLI) 命令(如果您可以運行一個Docker CLI 中的命令,您可以在 Podman CLI 中運行相同的命令)。

Podman 和 Buildah 的另一個不同之處是:Buildah 的容器主要是臨時創(chuàng)建的,以允許將內(nèi)容傳輸?shù)秸趧?chuàng)建的容器鏡像中,而使用 Podman,用戶創(chuàng)建傳統(tǒng)容器,旨在使用和維護更長時間. Buildah 的容器用于短期目的,而 Podman 的容器用于長期目的。

Buildah 和 Podman 各自創(chuàng)建的容器是互相看不到的。

4.安裝

4.1 CentOS

sudo yum -y install buildah

4.2 Ubuntu

# Ubuntu 20.10 and newer
sudo apt-get -y update
sudo apt-get -y install buildah

4.3 RHEL7

sudo subscription-manager repos --enable=rhel-7-server-extras-rpms
sudo yum -y install buildah

4.4 Fedora

sudo dnf -y install buildah

或者

$ sudo rpm-ostree install buildah
  • 更多安裝方式請參考這里[10]

5. 命令

Command

Description

buildah-add(1)[11]

將文件、URL 或目錄的內(nèi)容添加到容器中。

buildah-build(1)[12]

使用 Containerfiles 或 Dockerfiles 中的指令構(gòu)建鏡像。

buildah-commit(1)[13]

從運行的容器創(chuàng)建鏡像。

buildah-config(1)[14]

更新鏡像配置設(shè)置。

buildah-containers(1)[15]

列出工作容器及其基礎(chǔ)鏡像。

buildah-copy(1)[16]

將文件、URL 或目錄的內(nèi)容復制到容器的工作目錄中。

buildah-from(1)[17]

從頭開始或使用指定鏡像作為起點創(chuàng)建一個新的工作容器。

buildah-images(1)[18]

列出本地存儲中的鏡像。

buildah-info(1)[19]

顯示 Buildah 系統(tǒng)信息。

buildah-inspect(1)[20]

檢查容器或鏡像的配置。

buildah-mount(1)[21]

掛載工作容器的根文件系統(tǒng)。

buildah-pull(1)[22]

從指定位置拉取鏡像。

buildah-push(1)[23]

將鏡像從本地存儲推送到其他地方。

buildah-rename(1)[24]

重命名本地容器

buildah-rm(1)[25]

刪除一個或多個工作容器。

buildah-rmi(1)[26]

刪除一個或多個鏡像.

buildah-run(1)[27]

在容器內(nèi)運行命令。

buildah-tag(1)[28]

為本地鏡像添加一個額外的名稱。

buildah-umount(1)[29]

卸載工作容器的根文件系統(tǒng)。

buildah-unshare(1)[30]

在具有修改后的 ID 映射的用戶命名空間中啟動命令。

buildah-version(1)[31]

顯示 Buildah 版本信息

6. 示例

配置別名

$ vim /root/.bashrc
alias p='podman'
alias b='buildah'
alias s='skopeo'

6.1 命令行構(gòu)建一個 httpd 鏡像

第一步是提取基本映像并創(chuàng)建工作容器

$ buildah from fedora
fedora-working-container

$ b ps
CONTAINER ID BUILDER IMAGE ID IMAGE NAME CONTAINER NAME
89704476b76a * 885d2b38b819 registry.fedoraproject.org/fe... fedora-working-container

將包添加到工作容器

buildah run fedora-working-container dnf install httpd -y

為Web服務器創(chuàng)建包含某些內(nèi)容的工作目錄:

mkdir demo-httpd && cd demo-httpd && echo 'sample container' > index.html

將本地文件復制到工作容器

buildah copy fedora-working-container index.html /var/www/html/index.html

定義容器入口點以啟動應用程序

buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" fedora-working-container

配置完成后,保存鏡像:

buildah commit fedora-working-container fedora-myhttpd

列出本地鏡像

$ buildah images
REPOSITORY TAG IMAGE ID CREATED SIZE
localhost/fedora-myhttpd latest e1fb00a4662b 43 seconds ago 434 MB

現(xiàn)在可以使用podman在本地利用新生成的鏡像運行容器:

podman run -tid fedora-myhttpd

測試

$ p exec -ti heuristic_solomon curl http://localhost
sample container

要將映像推送到本地Docker倉庫,請執(zhí)行以下操作:

#登陸倉庫
$ buildah login -u registryuser -p registryuserpassword 192.168.10.80:5000
Login Succeeded!
#推送
$ buildah push fedora-myhttpd docker://192.168.10.80:5000/testuser/fedora-myhttpd:latest
Getting image source signatures
Copying blob d4222651a196 done
Copying blob cc6656265656 done
Copying config e1fb00a466 done
Writing manifest to image destination
Storing signatures

也可以這樣執(zhí)行:

buildah push --creds registryuser:registryuserpassword fedora-myhttpd docker://192.168.10.80:5000/testuser/fedora-myhttpd:latest

Skopeo檢查結(jié)果

$ skopeo inspect docker://192.168.10.80:5000/testuser/fedora-myhttpd:latest

6.2 Dockerfile 構(gòu)建

$ mkdir fedora-http-server && cd fedora-http-server 
$ nano Dockerfile
# Base on the most recently released Fedora
FROM fedora:latest
MAINTAINER ipbabble email buildahboy@redhat.com # not a real email

# Install updates and httpd
RUN echo "Updating all fedora packages"; dnf -y update; dnf -y clean all
RUN echo "Installing httpd"; dnf -y install httpd && dnf -y clean all

# Expose the default httpd port 80
EXPOSE 80

# Run the httpd
CMD ["/usr/sbin/httpd", "-DFOREGROUND"]

按CTRL+X退出,按Y保存,按Enter退出nano

構(gòu)建

buildah bud -t fedora-http-server

運行容器

podman run -p 8080:80  -tid fedora-http-server
podman ps

測試訪問

curl localhost:8080

6.3 構(gòu)建鏡像腳本(代替 Dockerfile)

  • build_buildah_upstream.sh
#!/usr/bin/env bash
# build_buildah_upstream.sh
#
ctr=$(buildah from fedora)
buildah config --env GOPATH=/root/buildah $ctr
buildah run $ctr /bin/sh -c 'dnf -y install --enablerepo=updates-testing \
make \
golang \
bats \
btrfs-progs-devel \
device-mapper-devel \
glib2-devel \
gpgme-devel \
libassuan-devel \
libseccomp-devel \
git \
bzip2 \
go-md2man \
runc \
fuse-overlayfs \
fuse3 \
containers-common; \
mkdir -p /root/buildah; \
git clone https://github.com/containers/buildah /root/buildah/src/github.com/containers/buildah; \
cd /root/buildah/src/github.com/containers/buildah; \
make; \
make install; \
rm -rf /root/buildah/*; \
dnf -y remove bats git golang go-md2man make; \
dnf clean all'

buildah run $ctr -- sed -i -e 's|^#mount_program|mount_program|g' -e '/additionalimage.*/a "/var/lib/shared",' /etc/containers/storage.conf

buildah run $ctr /bin/sh -c 'mkdir -p /var/lib/shared/overlay-images /var/lib/shared/overlay-layers; touch /var/lib/shared/overlay-images/images.lock; touch /var/lib/shared/overlay-layers/layers.lock'

buildah config --env _BUILDAH_STARTED_IN_USERNS="" --env BUILDAH_ISOLATION=chroot $ctr
buildah commit $ctr buildahupstream

構(gòu)建鏡像:

chmod 755 build_buildah_upstream.sh
./build_buildah_upstream.sh

運行容器:

$ podman run buildahupstream buildah version
$ podman run buildahupstream bash -c "buildah from busybox; buildah images"

參考:

  • Building Images With Buildah[32]
  • Building with Buildah: Dockerfiles, command line, or scripts[33]

引用鏈接

[1] Buildah: https://buildah.io/

[2] 容器: https://www.redhat.com/en/topics/containers/whats-a-linux-container

[3] Docker: https://www.redhat.com/en/topics/containers/what-is-docker

[4] Kubernetes: https://www.redhat.com/en/topics/containers/what-is-kubernetes

[5] 容器倉庫: https://www.redhat.com/en/topics/cloud-native-apps/what-is-a-container-registry

[6] 運行時環(huán)境: https://www.redhat.com/en/topics/cloud-native-apps/what-is-a-Java-runtime-environment

[7] Dockerfiles: https://blog.csdn.net/xixihahalelehehe/article/details/107517710

[8] Docker Hub: https://hub.docker.com/

[9] Podman: https://podman.io/

[10] 更多安裝方式請參考這里: https://github.com/containers/buildah/blob/main/install.md

[11] buildah-add(1): /https://github.com/containers/buildah/blob/main/docs/buildah-add.1.md

[12] buildah-build(1): https://github.com/containers/buildah/blob/main/docs/buildah-build.1.md

[13] buildah-commit(1): https://github.com/containers/buildah/blob/main/docs/buildah-commit.1.md

[14] buildah-config(1): https://github.com/containers/buildah/blob/main/docs/buildah-config.1.md

[15] buildah-containers(1): https://github.com/containers/buildah/blob/main/docs/buildah-containers.1.md

[16] buildah-copy(1): https://github.com/containers/buildah/blob/main/docs/buildah-copy.1.md

[17] buildah-from(1): https://github.com/containers/buildah/blob/main/docs/buildah-from.1.md

[18] buildah-images(1): https://github.com/containers/buildah/blob/main/docs/buildah-images.1.md

[19] buildah-info(1): https://github.com/containers/buildah/blob/main/docs/buildah-info.1.md

[20] buildah-inspect(1): https://github.com/containers/buildah/blob/main/docs/buildah-inspect.1.md

[21] buildah-mount(1): https://github.com/containers/buildah/blob/main/docs/buildah-mount.1.md

[22] buildah-pull(1): https://github.com/containers/buildah/blob/main/docs/buildah-pull.1.md

[23] buildah-push(1): https://github.com/containers/buildah/blob/main/docs/buildah-push.1.md

[24] buildah-rename(1): https://github.com/containers/buildah/blob/main/docs/buildah-rename.1.md

[25] buildah-rm(1): https://github.com/containers/buildah/blob/main/docs/buildah-rm.1.md

[26] buildah-rmi(1): https://github.com/containers/buildah/blob/main/docs/buildah-rmi.1.md

[27] buildah-run(1): https://github.com/containers/buildah/blob/main/docs/buildah-run.1.md

[28] buildah-tag(1): https://github.com/containers/buildah/blob/main/docs/buildah-tag.1.md

[29] buildah-umount(1): https://github.com/containers/buildah/blob/main/docs/buildah-umount.1.md

[30] buildah-unshare(1): https://github.com/containers/buildah/blob/main/docs/buildah-unshare.1.md

[31] buildah-version(1): https://github.com/containers/buildah/blob/main/docs/buildah-version.1.md

[32] Building Images With Buildah: https://docs.oracle.com/en/operating-systems/oracle-linux/podman/podman-BuildingImagesWithBuildah.html#buildah-containers

[33] Building with Buildah: Dockerfiles, command line, or scripts: https://www.redhat.com/sysadmin/building-buildah


責任編輯:武曉燕 來源: 愛死亡機器人
相關(guān)推薦

2020-05-06 22:07:53

UbuntuLinux操作系統(tǒng)

2023-11-06 07:21:02

DBaaSApachealpha版本

2022-08-15 11:44:49

RufusWindows工具

2021-08-30 06:27:21

工具容器Docker

2020-08-31 09:51:19

容錯系統(tǒng)開源開源工具

2016-02-16 13:21:33

2021-06-28 14:13:35

Jenkins服務器程序

2019-11-07 09:00:39

Jenkins流水線開源

2017-09-26 15:27:57

開源TiDB代碼

2021-03-05 11:35:39

Linux 命令工具

2016-10-08 15:03:17

OracleJavaScript開源工具

2022-10-09 08:15:14

算法智能運維

2019-09-10 13:34:30

Linux操作系統(tǒng)軟件

2023-09-04 08:26:08

手機開源Android

2023-04-06 07:09:25

自動化部署Actions

2022-02-25 19:29:07

Vue2esbuild項目

2022-08-02 20:21:42

開源項目工具

2022-03-28 08:11:00

鏡像分發(fā)網(wǎng)絡(luò)

2019-11-07 10:02:33

開源開源工具DevOps

2023-02-06 09:44:35

美圖開源kv存儲
點贊
收藏

51CTO技術(shù)棧公眾號