iT邦幫忙

2026 iThome 鐵人賽

DAY 24
0

若有公用開發環境兼包版環境,可以考慮引進.image與.build。這通常不會用在SIT/UAT。

# nginx.image

[Image]
Image=docker.io/library/nginx:1.28.0

而引用.image的.container方式如下:指定image為nginx.image。

# nginx.container

[Container]
Image=nginx.image
ContainerName=nginx

最主要也沒有registry機制,所以.image的實用價值著實不高。


而.build比較像把第五天的文章,把Dockerfile包image的動作交給Quadlet處理,若有專屬的開發環境如RedHat或Rocky Linux,倒是可以引進。

# ~/.config/containers/systemd/a2a-web.build
[Build]
ImageTag=localhost/a2a-web:latest
File=/home/appuser/a2a/a2a-web/Containerfile
SetWorkingDirectory=/home/appuser/a2a/a2a-web

而Containerfile就是Dockerfile的內容,在/home/appuser/a2a/a2a-web目錄下有nginx.conf檔及html和modules子目錄作為Containerfile複製之用。

FROM registry.suse.com/suse/nginx:latest

# 清掉預設網站內容
RUN rm -rf /srv/www/htdocs/*

# 複製 React build 輸出
COPY html/ /srv/www/htdocs/
COPY modules/ /srv/www/htdocs/modules/

# 自訂 nginx 設定
COPY nginx.conf /etc/nginx/nginx.conf

EXPOSE 80

STOPSIGNAL SIGQUIT

CMD ["nginx", "-g", "daemon off;"]

這樣經過systemctl --user daemon-reload後再執行systemctl --user start a2a-web.build這個動作,相當於在開發主機的上/home/appuser/a2a/a2a-web目錄下有做了:
podman build -t localhost/a2a-web:latest .
要注意systemctl --user start a2a-web.build並不是啟動容器,只是包出新的image而已。


那這樣有衍生一個有趣的問題,Containerfile的FROM可不可以指向nginx.image?答案是不行。可以迂迴做到間接引用nginx.image。
首先把FROM接的image值改為localhost/nginx:latest,就是引用本機的nginx image。
而.image應該如何設定:

# nginx.image

[Image]
Image=registry.suse.com/suse/nginx:latest
ImageTag=localhost/nginx:latest

systemctl --user daemon-reload後再執行systemctl --user start nginx-image.service這個動作。若systemctl --user start nginx-image.service執行過久,可能是開發環境是離線關係,nginx.image預設要做podman pull,所以確認registry.suse.com/suse/nginx:latest 這個image有在開發環境上的話,可以在nginx.image加個Policy=never。

# nginx.image

[Image]
Image=registry.suse.com/suse/nginx:latest
ImageTag=localhost/nginx:latest
Policy=never

上一篇
.kube的飯粒
下一篇
.artifact的前導知識:OCI
系列文
Podman Quadlet-容器服務化(在單體系統到微服務之間)28
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言