DEV Community

Pramoth Suwanpech
Pramoth Suwanpech

Posted on

2 1

รัน OCI Container ด้วย runc

runc เป็น command line interface (CLI) ที่เอาไว้รัน container ที่เป็นไปตาม spec ของ OCI ซึ่งใน CentOS 8 มีติดตั้งมาให้เรียบร้อย (น่าจะเพราะว่า podman ใช้)

ในตัวอย่างนี้ เราจะเอา Docker container มาทำให้อยู่ในรุปแบบ OCI format จากนั้นก็ run container ตัวใหม่เราได้เลย ซึ่งในตัวอย่างนี้จะใช้ podman แทน docker นะครับ

mkdir my-container
cd my-container

#rootfs จะเป็น os / ของ container
mkdir rootfs

# สร้าง docker container และ export container ไปไว้ใน rootfs
podman  export $(podman create ubuntu) | tar -C rootfs -xf -

#สร้าง OCI config file
runc spec

เมื่อ runc spec จะได้ไฟล์ config.json ซึ่งเราสามารถแก้ไขตามต้องการได้ ในตัวอย่างนี้ผมแก้จาก container เดิมที่ start shell เป็นพิมพ์ os-release ออกมา โดยแก้ดังนี้

 "args": [
                        "cat","/etc/os-release"
          ],

เมื่อแก้เสร็จก็พร้อมรันได้เลย

sudo runc run my-ubuntu

โดย my-ubuntu เป็นชื่อของ container
ได้ผลลัพธ์ดังนี้

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bioni

เพิ่มเติม
https://github.com/opencontainers/runc

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Engage with a sea of insights in this enlightening article, highly esteemed within the encouraging DEV Community. Programmers of every skill level are invited to participate and enrich our shared knowledge.

A simple "thank you" can uplift someone's spirits. Express your appreciation in the comments section!

On DEV, sharing knowledge smooths our journey and strengthens our community bonds. Found this useful? A brief thank you to the author can mean a lot.

Okay