iT邦幫忙

2025 iThome 鐵人賽

DAY 20
0
Cloud Native

駕馭商用容器叢集,汪洋漂流術系列 第 20

【Day 20】 自製容器, Linux 以外的環境,運行 oc-mirror

  • 分享至 

  • xImage
  •  

前言

在本系列 【Day 17】 私有 Quay Registry 與 oc mirror 提到用 oc-mirror

說明

  • 在慣用的 MacOS 下沒有 oc-mirror,不過因為開發需求,要使用乾坤大挪移時會很麻煩。
  • 系統不符? 那不就可以用容器來提供需要的環境就好了?!

準備容器

取得原始碼

  • 到 oc-mirror 的 GitHub 頁面,clone 源碼
    • 連結:https://github.com/openshift/oc-mirror
  • 在特定開發目錄下,運作指令
    git clone https://github.com/openshift/oc-mirror
    

Dockerfile

  • 同一個目錄下,寫一支 Dockerfile,內容如下:
    # 使用 Red Hat UBI 基礎映像
    FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
    
    # 設定工作目錄
    WORKDIR /usr/local/bin
    
    # 複製 oc-mirror binary (需自行放到 build context)
    COPY oc-mirror /usr/local/bin/oc-mirror
    
    # 確保 binary 有執行權限
    RUN chmod +x /usr/local/bin/oc-mirror
    
    # 預設工作目錄 (給使用者掛載 config/output)
    WORKDIR /workspace
    
    # 預設 entrypoint
    ENTRYPOINT ["oc-mirror"]
    

建立 Image

  • 用 docker 或 podman 來做
# 假設 Dockerfile 與 oc-mirror binary 在同一個目錄
docker build -t oc-mirror:latest .

  • 測試包好的 Image 是否可用
docker run --rm -it oc-mirror:latest version

完成

  • 掛載對應的東西,直接使用
docker run --rm -it \
  -v $(pwd)/config.yaml:/config.yaml \
  -v $(pwd)/mirror-data:/mirror-data \
  oc-mirror:latest --config /config.yaml file://mirror-data

上一篇
【Day 19】 從 Docker 棄坑、你需要使用 Podman 的理由
下一篇
【Day 21】 認識叢集的四大監控與觀測工具
系列文
駕馭商用容器叢集,汪洋漂流術21
圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言