将 MS Edit 的 Docker 容器发布到 GitHub 容器注册表
Publishing a Docker Container for MS Edit to the GitHub Container Registry

原始链接: https://til.simonwillison.net/github/container-registry

我想要在我的苹果硅Mac上运行微软新的Edit终端文本编辑器,尽管没有官方的版本。我使用了Docker在一个容器中运行aarch64-linux-gnu版本。最初,我使用Ubuntu和Alpine基础镜像的单行shell命令,但由于每次运行都要安装软件包,所以速度很慢。 为了改进这一点,我创建了一个使用Alpine和`gcompat`(用于glibc兼容性)的多阶段Docker构建。构建阶段下载并解压Edit,而最终阶段只安装运行时依赖项并复制Edit二进制文件。这使得镜像更小更快。 最后,我将镜像发布到了GitHub容器注册表。在生成一个具有write:packages和read:packages访问权限的PAT(个人访问令牌)后,我登录,标记镜像并推送。然后将软件包可见性设置为公开。我还创建了一个包含Dockerfile和使用说明的仓库。现在,任何在苹果硅Mac上安装了Docker的人都可以使用以下命令在本地文件上运行Edit:`docker run --platform linux/arm64 -it --rm -v $(pwd):/workspace ghcr.io/simonw/alpine-edit`

Hacker News上的讨论围绕着一个将MS Edit的Docker容器发布到GitHub Container Registry的帖子展开。评论者们开玩笑说人们为了避免使用Vim或Emacs而付出了多大的努力。有人提出了一个问题:如何在不拥有源代码的情况下自动同步GitHub仓库的克隆,建议包括fork仓库并使用预定的GitHub Actions来检查上游更新并同步fork。此同步需要个人访问令牌 (PAT) 来触发新的构建。一位用户描述了他们的仓库只包含构建脚本,并且预定的CI作业会检查上游是否有更改的设置。另一位评论者开玩笑地建议等几十年以数十亿美元的价格收购nano。整体语气轻松愉快,重点关注容器化和自动化更新的实用解决方案。
相关文章

原文

Microsoft recently released Edit, a new terminal text editor written in Rust. It's pretty nice - it's reminiscent of nano but with a retro MS DOS feel.

I wanted to run it on my Apple Silicon Mac. Microsoft don't (yet) provide compiled builds for that platform, but they do have a release for aarch64-linux-gnu. I figured I'd run that in o Docker container (I have Docker for Desktop installed) to try it out.

One thing lead to another and I ended up creating and shipping a new Docker image to GitHub's Container Registry. This means anyone with an Apple Silicon Mac and Docker can try out edit against the files in their current directory by running this command:

docker run --platform linux/arm64 -it --rm -v $(pwd):/workspace ghcr.io/simonw/alpine-edit

Hit Ctrl+Q or use your mouse to acces File -> Exit to exit the editor and terminate the container.

Screenshot of the Edit text editor showing the File menu

I did almost all of my figuring out for this project in this 25 minute Claude Conversation. This post is the edited highlights of what I learned.

Running it first as a one-liner

I started by figuring out a shell one-liner for running the binary. This took a few tries - it turned out Microsoft's compiled binary needed glibc and my first choice of base image, alpine, used musl instead.

I got it working using an Ubuntu base image like this:

docker run --platform linux/arm64 -it --rm \
  -v $(pwd):/workspace \
  -w /workspace ubuntu:latest sh -c "
    apt update && \
    apt install -y zstd curl && \
    curl -L https://github.com/microsoft/edit/releases/download/v1.2.0/edit-1.2.0-aarch64-linux-gnu.tar.zst -o edit.tar.zst && \
    zstd -d edit.tar.zst && \
    tar -xf edit.tar && \
    chmod +x edit && \
    exec bash"

Running this command drops you into Bash in the container - running ./edit then opens the editor.

I managed to get Alpine working too by having it install the gcompat package:

docker run --platform linux/arm64 -it --rm \
  -v $(pwd):/workspace \
  -w /workspace alpine:latest sh -c "
    apk add --no-cache zstd curl gcompat && \
    curl -L https://github.com/microsoft/edit/releases/download/v1.2.0/edit-1.2.0-aarch64-linux-gnu.tar.zst -o edit.tar.zst && \
    zstd -d edit.tar.zst && \
    tar -xf edit.tar && \
    chmod +x edit && \
    exec sh"

Both of these examples take a little while to start as they download a bunch of extra packages every time. I decided to build a reusable image instead.

A multi-stage Docker build

I decided to use Alpine with the gcompat package as it's smaller than using Ubuntu. I told Claude to use a multi-stage build because I didn't want the zstd and curl binaries in the final image, just the edit binary itself.

Here's what we got to:

# Build stage - download and extract the binary
FROM alpine:latest AS builder

# Install tools needed for download/extraction
RUN apk add --no-cache zstd curl

# Download and extract the edit binary
RUN curl -L https://github.com/microsoft/edit/releases/download/v1.2.0/edit-1.2.0-aarch64-linux-gnu.tar.zst -o /tmp/edit.tar.zst \
    && zstd -d /tmp/edit.tar.zst \
    && tar -xf /tmp/edit.tar -C /tmp/ \
    && chmod +x /tmp/edit

# Final runtime stage - minimal image
FROM alpine:latest

# Install only runtime dependencies
RUN apk add --no-cache \
    gcompat \
    libgcc \
    && rm -rf /var/cache/apk/*

# Copy the binary from build stage
COPY --from=builder /tmp/edit /usr/local/bin/edit

# Set working directory
WORKDIR /workspace

# Set the edit binary as the entrypoint
ENTRYPOINT ["/usr/local/bin/edit"]

# Default to current directory if no args provided
CMD ["."]

This has the added bonus that it uses /usr/local/bin/edit as the entrypoint, which means just starting the container will drop you directly into the editor.

I built it like this:

docker build --platform linux/arm64 -t alpine-edit .

And then tested it with this command:

docker run --platform linux/arm64 -it --rm -v $(pwd):/workspace alpine-edit

Publishing to the GitHub Container Registry

GitHub offer a free container registry that can be used to distribute Docker images. I've never tried that before, so this felt like a good opportunity to learn how to use it.

First I needed a GitHub Personal Access Token (PAT) with the right permissions to publish to the registry.

  1. GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic) - this page here
  2. Create a new token with these scopes:
    • write:packages
    • read:packages

I logged into the GitHub Container Registry using this command:

docker login ghcr.io -u simonw --password-stdin

I pasted in the token, then hit enter (and nothing happened), then hit Ctrl+D to finish the login. That seemed to work.

I built the image again with a tag for the GitHub Container Registry:

docker build --platform linux/arm64 -t ghcr.io/simonw/alpine-edit:latest .

Then pushed it to the registry with this command:

docker push ghcr.io/simonw/alpine-edit:latest

The published package become available at github.com/users/simonw/packages/container/package/alpine-edit - that page defaulted to private but I clicked on "Package settings" and toggled the visibility to "Public".

Final step: I created an accompanying repository at github.com/simonw/alpine-edit with the Dockerfile and a README.md explaining how to use it, then used the "Connect Repository" button on the package page to link the two together.

Created 2025-06-21T11:16:26-07:00, updated 2025-06-21T13:35:20-07:00 · History · Edit

联系我们 contact @ memedata.com