Computer >> Hướng Dẫn Máy Tính >  >> Hệ Thống >> Linux

Hướng dẫn người mới bắt đầu Podman Containers trên Linux

Khi nói về Future of Technology, nhiều tech giàu kinh nghiệm biết virtualization và containerization là con đường đó. Chúng cho phép application/service security tốt hơn, dễ manage qua service khác cho snapshotting, templates, customization hơn model one-server-per-application. Tuy nhiên, không luôn rõ ràng cách bắt đầu virtualization và containerization. Chúng tôi cover virtualization trên Linux, Windows, macOS nhiều lần, nhưng containerization hơi different beast. Bài viết cung cấp beginner's guide Podman trên Linux, tool tuyệt vời cho containerization.

Container là gì?

Container về cơ bản là little virtual machines – nhưng chỉ cho application. Dùng nhiều concept giống nhau, mang security và ease-of-use features tương tự, nhưng nhỏ hơn nhiều và cho phép easy imaging và distribution application. Đây là cơ sở của Flatpaks và Snaps. Bắt đầu thấy parallel: one program, multiple application chạy trong isolated environment.

Podman là gì?

Nhiều người nghe Docker, OG của container engine. Podman là container engine tương tự dùng structure rất giống Docker với vài key difference.

Một: Podman daemonless, trong khi Docker rely on daemon. Nghĩa là Podman container chạy không cần root permission, cho more security và flexibility. Container chạy ở user level → user chỉ thấy container của họ, không phải người khác. Podman nhẹ system resources hơn do architecture đơn giản, trải nghiệm enjoyable hơn.

Kiến trúc daemonless dẫn đến rootless containers. Concept xây dựng trên difference trước nhưng focus security. Nếu attacker compromise container và escape vì lý do gì, họ chỉ có basic user permission thay vì root permission. Cần setup thêm để chạy, và có một số shortcoming hiện tại, nhưng worth a look.

Cài đặt Podman

Đa số distro, Podman có trong main repo, cài đơn giản:

# Debian/Ubuntu
sudo apt install podman
# Fedora/CentOS/Redhat
sudo dnf install podman
# Arch Linux
sudo pacman -S podman
# OpenSUSE
sudo zypper install podman
# Gentoo
sudo emerge app-emulation/podman

Dùng Podman

Cú pháp command start Podman container hơi confusing, nhưng khi nắm pattern, bạn nhận ra quy luật. Có sample container từ project chạy bằng lệnh terminal:

podman run -dt -p 8080:8080/tcp -e HTTPD_VAR_RUN=/run/httpd -e HTTPD_MAIN_CONF_D_PATH=/etc/httpd/conf.d \
-e HTTPD_MAIN_CONF_PATH=/etc/httpd/conf \
-e HTTPD_CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/httpd/ \
registry.fedoraproject.org/f29/httpd /usr/bin/run-httpd

Sẽ pull image từ registry listed, xong thì ra long number. Sẽ thấy sau khi check running container.

Check running Podman container:

podman ps

Thấy container start trước. Xác nhận running. Muốn xem webpage Apache chạy, chạy:

curl https://0.0.0.0:8080

Thay 0.0.0.0 bằng IP address show khi chạy podman ps. Sẽ nhận bunch garbled HTML, nhưng nhìn top, thấy syntax title HTML biết nó chạy.

Test Page for the Apache HTTP Server on Fedora

Podman Images

Điều hay Podman: dùng images. Search image khác như httpd hoặc program bạn muốn chạy.

podman search CONTAINERNAME

Tác giả search vncserver, kết quả như hình. Nhiều option, tùy preference.

Grab image đó, chạy podman pull:

podman pull CONTAINERNAME

Khuyên pull full url container registry để accurate. Ví dụ lệnh tác giả chạy:

podman pull docker.io/michaelaboeckler/vncserver

Thay vì chỉ podman pull vncserver vì có thể image không muốn được chọn thay vì cái muốn.

Check images:

podman images

Stop container:

podman stop -l

Flag -l stop latest run container, cũng dùng -a stop all container.

Có thể nhận ra Podman cũng look tại docker.io cho container image. Vì Podman command và Docker command essentially the same – similar đến mức khuyên alias docker thành podman:

alias docker='podman'

Nghĩa là bất kỳ lúc gõ docker, máy chạy podman anyway.

Rootless Podman

Setup hệ thống cho rootless container, có khá nhiều setup, nhưng documentation tốt trên Github page.

Hy vọng bạn thích primer Podman, tool nhỏ gọn chạy daemonless, rootless container giữ hệ thống lean, tidy, secure. Nếu thích, xem thêm container content: chạy Ubuntu trong container ChromeOS, copy Docker container sang host khác, limit Docker Container resources.