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

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay