在Proxmox 9.1中原生运行Docker容器(OCI镜像)
Run Docker containers natively in Proxmox 9.1 (OCI images)

原始链接: https://raymii.org/s/tutorials/Finally_run_Docker_containers_natively_in_Proxmox_9.1.html

## Proxmox VE 9.1 现在支持 Docker 容器(有一些限制) Proxmox VE,一个基于 Debian 的开源虚拟化平台,发布了 9.1 版本,包含一项重要的新功能:原生支持运行 Docker 容器。 之前,运行 Docker 需要一个完整的虚拟机,但 Proxmox 现在允许直接执行 OCI 镜像(例如来自 Docker Hub 的镜像)。 这并非*真正*的原生 Docker 支持;Proxmox 将 Docker 镜像转换为 LXC 容器。 这种解决方法解决了与 AppArmor 和其他系统组件的兼容性问题。 虽然很方便,但目前仍处于“技术预览”阶段——更新需要重新创建容器(无法简单地 `docker pull`),并且实时迁移/编排最好仍然在虚拟机中处理。 该过程涉及将镜像下载到 Proxmox 存储,然后从中创建一个容器,类似于设置标准的 LXC 容器。 虽然控制台功能可能有限,但可以通过 `pct enter` 访问。 此新功能有望简化容器部署,用于家庭实验室及其他环境,从而节省大量时间和资源。 作者是一位长期 Proxmox 用户,在 HP EliteDesk Minis 上运行一个 2 节点集群,他强调这是一个重大改进,并希望未来支持 Docker Compose 文件。 他最近还移除了网站上的 Google 跟踪,并欢迎捐赠以帮助支付服务器成本。

Hacker News 新闻 | 过去 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 在 Proxmox 9.1 中原生运行 Docker 容器 (OCI 镜像) (raymii.org) 13 分,由 jandeboevrie 发表于 25 分钟前 | 隐藏 | 过去 | 收藏 | 2 条评论 nirav72 发表于 10 分钟前 [–] 我今天试了一下这个。唯一缺点是,目前还没有简单的方法来更新容器。但另一方面,再也不用处理 macvlan 或自定义 docker 网络了。回复 dijit 发表于 0 分钟前 | 父评论 [–] “更新”,你指的是“用新镜像重新创建”吗?我认为 Docker 本身并不支持这个。回复 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Proxmox VE is a virtualization platform, like VMWare, but open source, based on Debian. It can run KVM virtual machines and Linux Containers (LXC). I've been using it for over 10 years, the first article I wrote mentioning it was in 2012. At home I have a 2 node Proxmox VE cluster consisting of 2 HP EliteDesk Mini machines, both running with 16 GB RAM and both an NVMe and SATA SSD with ZFS on root (256 GB). It's small enough (physically) and is just enough for my homelab needs specs wise. Proxmox VE 9.1 was released recently and this new version is able to run Docker containers / OCI images natively, no more hacks or VM's required to run docker. This post shows you how to run a simple container from a docker image.

Recently I removed all Google Ads from this site due to their invasive tracking, as well as Google Analytics. Please, if you found this content useful, consider a small donation using any of the options below. It means the world to me if you show your appreciation and you'll help pay the server costs:

GitHub Sponsorship

PCBWay referral link (You get $5, I get $20 after you've placed an order)

Digital Ocea referral link ($200 credit for 60 days. Spend $25 after your credit expires and I'll get $25!)

Introduction and info on Proxmox VE 9.1's OCI image feature

Linux Containers (LXC) in Proxmox VE behave more like a virtual machine than Docker containers, most of the time. A Docker container runs one application, an LXC container runs a whole slew (init system, ssh, an entire distribution). For as long as I can remember, Proxmox VE has no official way of running Docker containers natively. They recommend to run docker inside a Proxmox QEMU virtual machine. Sometimes (recently), Docker-inside-LXC actually breaks.

But nobody wants to manage an entire VM just to play around with some containers and running Docker directly on your Proxmox VE host is a bad idea as well.

They did something quite clever. They sort of convert the container image to a full fledged LXC image. In some place it seems that skopeo is used.

Quoting a forum post with more info:

May I ask why docker LXC's are a no-no?

Generally this causes issues between our use of Apparmor and other parts of our code base over and over again. So we heavily discourage it. However, with the release of Proxmox VE 9.1 you can use OCI templates for application containers on Proxmox VE.

This means that you can run Docker containers as application containers on Proxmox VE like you would any other LXC container. It works by translating the Docker images (which are OCI images) to LXC containers on Proxmox VE.

Not everything works yet, this is still a tech preview as of writing:

While it can be convenient to run "Application Containers" directly as Proxmox Containers, doing so is currently a tech preview. For use cases requiring container orchestration or live migration, it is still recommended to run them inside a Proxmox QEMU virtual machine.

In the current technology preview state of our OCI image support, all layers are squashed into one rootfs upon container creation. Because of this, you currently cannot update a container simply by swapping in a newer image

So technically the title of this article is wrong, you aren't running Docker containers natively, they're converted. But for what it's worth, it saves so much time already. Now only if Proxmox VE supported docker-compose files, that would be even more amazing.

Upgrading containers (a docker pull) isn't straightforward ( yet), it requires fiddling with data volumes and re-creating a container. The console also does not provide a shell in most containers, it just shows the stdout/in of the main init process.

Running pct enter xxx did drop me inside a working shell in the converted container.

Starting an OCI image in Proxmox VE 9.1.1

Make sure you've updated Proxmox VE to at least 9.1.1.

Starting a docker container (OCI image, I'll use these terms interchangeably in this article) consists of two steps, first you must download the image to template storage, then you can create a container from that image.

Navigate to your storage and click the Pull from OCI Registry button:

storage step 1

Enter the full URL to a container image. For example, docker.io/eclipse-mosquitto:

storage step 2

(If you spell the URL wrong you'll get weird errors, I got a few errors mentioning "Unauthorized", while I just had a typo in the reference, nothing to do with authorization).

Click the Download button and watch the image being pulled:

storage step 3

That was the storage part. Now the container part. Click the Create CT button, fill in the first tab and on the second (Template) tab, select the OCI image we've just downloaded:

ct step 1

On the Disks tab, you can add extra volumes under a mount point, in this case for the mosquitto configuration:

ct step 2

This is comparable with the -v option when running docker containers to mount a local directory inside a container

Fill in the other tabs as you would normally do. This is the summary page:

ct step 3

In the Create task output you can see that Proxmox VE detected that the image is an OCI container / Docker image. It will do some extra stuff to "convert" it to an LXC container:

ct step 4

That's all there is to it. You can now start your container and enjoy all the features you would normally get from an LXC container managed by Proxmox VE.

The console shows an extra notification regarding this being an OCI image based container:

ct console

In my case the console did not work, as mentioned earlier, but I was able to enter the container just fine:

ct enter

After editing the mosquitto config (on the /mosquitto/config volume) and restarting the container I was able to connect just fine:

mosquitto

# example config:
listener 1883
allow_anonymous true

Environment variables are available in the Options tab once the container is created:

env vars

(but currently not during initialization)

I also tried the official nginx docker container image, that worked just fine as well. This will be a major time saver when running containers.

Tags: docker , homelab , kvm , linux , lxc , oci , proxmox , proxmox-ve , qemu , sysadmin , tutorials , virtualization
联系我们 contact @ memedata.com