메뉴
HN
Hacker News 49일 전

macOS를 위한 컨테이너 머신

IMP
7/10
핵심 요약

Mac 환경에서 완벽하게 통합되는 가볍고 빠른 Linux 환경을 제공하는 도구입니다. 개발자는 Mac의 기본 에디터와 도구를 그대로 사용하면서 Linux 기반의 빌드 및 테스트를 수행할 수 있어 작업 흐름이 크게 간소화됩니다. 특히 호스트의 홈 디렉토리를 자동 공유하고 표준 OCI 이미지를 기반으로 하여 다양한 배포판 환경을 손쉽게 구축할 수 있다는 점이 핵심적인 장점입니다.

번역된 본문

컨테이너 머신(Container machine)은 Mac에서 원활하게 작동하는 고도로 통합된 Linux 환경을 제공합니다. 컨테이너 머신은 빠르고, 가볍으며, 상태가 유지됩니다(persistent). 이들은 빌드 및 공유가 가능한 표준 OCI 이미지를 기반으로 합니다. 자동 사용자 및 홈 디렉토리 공유와 같은 호스트 통합 기능은 터미널의 어느 위치에 있든 Linux 환경에 빠르고 쉽게 접근할 수 있게 해줍니다.

왜 컨테이너 머신인가? 컨테이너는 일반적으로 애플리케이션을 모델링합니다. 컨테이너 머신은 Linux 환경 자체를 모델링합니다. 이미지의 init 시스템을 실행하므로 장기 실행 서비스를 등록하거나 프로세스 감독자 하에서 애플리케이션을 테스트할 수 있습니다. 컨테이너 머신은 사용자의 사용자 이름과 홈 디렉토리를 Linux 환경에 자동으로 매핑합니다. 저장소와 dotfiles가 두 플랫폼 모두에서 사용 가능합니다. Linux 환경 내부에서 빌드하고 실행하는 동시에 macOS에서 직접 편집기와 도구를 사용하세요. Mac에서 편집하고, 내부에서 빌드하세요. 저장소는 macOS의 $HOME에 있으며 컨테이너 머신 내부의 /Users/<사용자 이름>에 마운트됩니다. macOS 에디터나 IDE를 사용하고; 컨테이너 머신 내부에서 컴파일하고 실행하세요.

Linux 산출물(Artifacts)에 대해 macOS 네이티브 도구를 사용하세요. Mac의 프로파일러, 스크린샷 도구, 브라우저 및 GUI 디버거는 컨테이너 머신이 보는 것과 동일한 파일을 봅니다. 즉, "빌드 완료"와 "검사 시작" 사이에 복사 단계가 없습니다.

테스트를 위한 실제 Linux 서비스. 데이터베이스나 스택에 필요한 모든 것을 시스템 서비스로 실행하세요. systemctl start postgresql은 systemd가 설치된 이미지에서 작동합니다.

대상 배포판별로 하나의 환경을 구축하세요. 대상 배포판(alpine, ubuntu, debian 등)의 수만큼 컨테이너 머신을 생성하세요. 모두 Mac과 동일한 $HOME과 동일한 dotfiles를 가집니다. 다양한 배포판에서 애플리케이션을 빠르게 테스트해 보세요.

빠른 시작 container machine create alpine:latest --name dev container machine run -n dev whoami # 호스트 사용자 이름이 반환되며 root가 아닙니다 container machine run -n dev pwd # /home/<사용자> — Mac의 홈 디렉토리가 컨테이너 머신에 마운트됩니다 container machine run -n dev # 대화형 셸 진입; $HOME에 있는 저장소로 cd container machine run은 셸을 얻거나 단일 명령을 실행하는 방법입니다. 컨테이너 머신이 중지된 경우 run이 먼저 이를 부팅합니다.

컨테이너 머신에서 작업하기 셸 열기 또는 단일 명령 실행 명령 없이 실행하면 container machine run은 호스트 계정과 일치하는 사용자로 대화형 셸을 엽니다. container machine run -n dev 명령을 전달하여 한 번 실행하고 종료할 수 있습니다: container machine run -n dev uname -a container machine run -n dev -- cat /proc/cpuinfo

기본값 설정 -n 플래그를 생략할 수 있도록 기본 컨테이너 머신을 선택하세요: container machine set-default dev container machine run # dev 환경에서 작동

나열, 검사, 중지, 삭제 container machine ls # 모든 컨테이너 머신 나열 container machine inspect dev # 하나의 컨테이너 머신에 대한 JSON 세부 정보 container machine stop dev # 컨테이너 머신 중지 container machine rm dev # 영구 스토리지를 포함하여 삭제 container machine은 m이라는 별칭이 있으므로 m ls, m run 등이 모두 작동합니다.

CPU, 메모리 크기 조정 또는 홈 마운트 변경 container machine set은 디스크의 구성을 업데이트합니다. 변경 사항은 다음 중지 및 시작 후에 적용됩니다: container machine set -n dev cpus=4 memory=8G container machine stop dev container machine run -n dev -- nproc 메모리 기본값은 호스트 메모리의 절반입니다. 홈 마운트는 rw(기본값), ro 또는 none일 수 있습니다.

나만의 컨테이너 머신 이미지 가져오기 /sbin/init이 포함된 모든 Linux 이미지는 컨테이너 머신으로 작동합니다. 예를 들어, 이 Dockerfile은 systemd와 일반적인 명령줄 도구가 포함된 Ubuntu 24.04 컨테이너 머신 이미지를 빌드합니다: FROM ubuntu:24.04 ENV container container RUN apt-get update &&
apt-get install -y
dbus systemd openssh-server net-tools iproute2 iputils-ping curl wget vim-tiny man sudo &&
apt-get clean &&
rm -rf /var/lib/apt/lists/* &&
yes | unminimize RUN >/etc/machine-id RUN >/var/lib/dbus/machine-id RUN systemctl set-default multi-user.target RUN systemctl mask
dev-hugepages

원문 보기
원문 보기 (영어)
Container machine Container machine provides a highly integrated Linux environment that works seamlessly on your Mac. Container machines are fast, lightweight and persistent. They are based on standard OCI images that can be built and shared. Host integrations such as automatic user and home directory sharing provide quick and easy access to your Linux environment no matter where you are in a terminal. Why container machines Containers are typically modeled after an application. A container machine is modeled after a Linux environment. It runs the image's init system allowing you to register long running services or test your application under a process supervisor. A container machine automatically maps your username and home directory into the Linux environment. Your repositories and dotfiles are available on both platforms. Use editors and tools directly on macOS simultaneously building and running your application inside of the Linux environment. Edit on the Mac, build inside. Your repo lives in $HOME on macOS and is mounted at /Users/<username> inside the container machine. Use your macOS editor or IDE; compile and run inside your container machine. Use macOS-native tooling against Linux artifacts. Profilers, screenshot tools, browsers, and GUI debuggers on your Mac all see the same files the container machine sees — there is no copy step between "I built it" and "I am inspecting it". Real Linux services for testing. Run a database or whatever your stack needs as a system service — systemctl start postgresql works on images with systemd installed. One environment per target distro. Create as many container machines as you have target distros — alpine , ubuntu , debian . Each has the same $HOME and the same dotfiles from your Mac. Quickly test your application in various distributions. Quickstart container machine create alpine:latest --name dev container machine run -n dev whoami # your host username, not root container machine run -n dev pwd # /home/<you> — your Mac home dir, mounted in container machine run -n dev # interactive shell; cd into your repos in $HOME container machine run is how you get a shell or run a single command. If the container machine is stopped, run boots it first. Working in a container machine Open a shell, or run a single command With no command, container machine run opens an interactive shell as a user that matches your host account: container machine run -n dev Pass a command to run it once and exit: container machine run -n dev uname -a container machine run -n dev -- cat /proc/cpuinfo Set a default Pick a default container machine so you can drop the -n flag: container machine set-default dev container machine run # operates on dev List, inspect, stop, delete container machine ls # list all container machines container machine inspect dev # JSON detail for one container machine stop dev # stop the container machine container machine rm dev # delete, including its persistent storage container machine has the alias m , so m ls , m run , etc. all work. Resize CPUs, memory, or change the home-mount container machine set updates configuration on disk. Changes take effect after the next stop and start: container machine set -n dev cpus=4 memory=8G container machine stop dev container machine run -n dev -- nproc Memory defaults to half of host memory. The home-mount can be rw (default), ro , or none . Bring your own container machine image Any Linux image that includes /sbin/init works as a container machine. For example, this Dockerfile builds an Ubuntu 24.04 container machine image with systemd and common command-line tools: FROM ubuntu:24.04 ENV container container RUN apt-get update && \ apt-get install -y \ dbus systemd openssh-server net-tools iproute2 iputils-ping curl wget vim-tiny man sudo && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* && \ yes | unminimize RUN >/etc/machine-id RUN >/var/lib/dbus/machine-id RUN systemctl set-default multi-user.target RUN systemctl mask \ dev-hugepages.mount \ sys-fs-fuse-connections.mount \ systemd-update-utmp.service \ systemd-tmpfiles-setup.service \ console-getty.service RUN systemctl disable \ networkd-dispatcher.service RUN sed -i -e 's/^AcceptEnv LANG LC_ \* $/#AcceptEnv LANG LC_*/' /etc/ssh/sshd_config Build it and create a container machine from it: container build -t local/ubuntu-machine:latest . container machine create local/ubuntu-machine:latest --name ubuntu By default, container runs a built-in setup script on first boot to provision the user described above. To use your own setup instead, add an executable script at /etc/machine/create-user.sh to the image. It runs once, as root, on first boot, with these variables set: CONTAINER_GID CONTAINER_HOME CONTAINER_MACHINE_ID CONTAINER_UID CONTAINER_USER
관련 소식