Taking Apple Container for a spin
I just heard about the new project from Apple, Container. It’s a tool that claims to make running Linux containers on Macs very simple. Read along try it out for the first time.
Download and Install
The first step to using container is to download a signed installer package from the GitHub release page
After downloading the installation was quick and easy
container command
Now that it is installed, I can launch a terminal and run the “container” command:
containerThere are a few different options that you can specify
OVERVIEW: A container platform for macOS
USAGE: container [--debug] <subcommand>
OPTIONS:
--debug Enable debug output [environment: CONTAINER_DEBUG]
--version Show the version.
-h, --help Show help information.
CONTAINER SUBCOMMANDS:
create Create a new container
delete, rm Delete one or more containers
exec Run a new command in a running container
inspect Display information about one or more containers
kill Kill one or more running containers
list, ls List containers
logs Fetch container stdio or boot logs
run Run a container
start Start a container
stop Stop one or more running containers
IMAGE SUBCOMMANDS:
build Build an image from a Dockerfile
images, image, i Manage images
registry, r Manage registry configurations
SYSTEM SUBCOMMANDS:
builder Manage an image builder instance
system, s Manage system componentsLet’s use the “system” subcommand to start the service:
container system startYou should expect to get something like this:
Verifying apiserver is running...
Installing base container filesystem...
No default kernel configured.
Install the recommended default kernel from [https://github.com/kata-containers/kata-containers/releases/download/3.17.0/kata-static-3.17.0-arm64.tar.xz]? [Y/n]:
Installing kernel...Hello World
Let’s see if we can create a simple container from a Dockerfile and run it. This is about as simple as it gets, create a file named “Dockerfile” and add this to it:
FROM alpine:latest
CMD ["echo","Hello World"]Now lets build the image:
container build --tag test --file Dockerfile .It took a while to build because it had to download the alpine image for the first time, but now I have an image! Here is the output:
[+] Building 1.8s (4/4) FINISHED
=> [resolver] fetching image...docker.io/library/alpine:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> oci-layout://docker.io/library/alpine:latest@sha256:8a1f59ffb675680d47db6337b49d22281a139e9d709335b492be023728e11715 0.1s
=> => resolve docker.io/library/alpine:latest@sha256:8a1f59ffb675680d47db6337b49d22281a139e9d709335b492be023728e11715 0.1s
=> => sha256:d69d4d41cfe2ee680d6972795e2a1eb9e4dc4ec3b3c5e0797c9ab43bb3726fa7 4.14MB / 4.14MB 0.0s
=> exporting to oci image format 0.1s
=> => exporting layers 0.0s
=> => exporting manifest sha256:9b0c095b0a85a2fa0b9c602cd979aeea437520a561767655d7d863b28ac35812 0.0s
=> => exporting config sha256:b76eaef5c14cbe329aca41fa7209eaadcbd20cc57af05e4cae258a1a5a288d9f 0.0s
=> => exporting manifest list sha256:0e0507df913a5e943b31e08370ab574db43e891801ac75e1df6a7d2e253e3015 0.0s
=> => sending tarball 0.0s
Successfully built test:latestI should be able to see it in my list of containers:
container image listOutput:
NAME TAG DIGEST
alpine latest 8a1f59ffb675680d47db6337...
test latest 0e0507df913a5e943b31e083...The “test” image that I built is listed and also the base image “alpine” that we used. There image are both on my machine now.
Let’s spin up a container named “hello-world” from the image “test”:
container run --name hello-world testThe output is exactly what we expect:
Hello WorldThis is a very simple example but it shows how easy it is to start using container on Mac.
Next Steps
Here is a sneak peak of what I’m going to do next with Apple container:
container run --name my-grafana grafana/grafana-oss