Tutorial: Setting Up and Exploring Apple Containerization on macOS

Wait 5 sec.

In a previous post, I introduced Apple Containers and compared it with Docker Desktop for macOS. In this tutorial, we will explore the CLI to run containers using native Apple Containerization technology on macOS 15 Sequoia.Step 1 – Installing the Container CLIDownload the latest version of the command line interface from https://github.com/apple/container/releases and run the package.Verify the installation with the command container --versionOnce the CLI is installed, start the API server with the command container system startStep 2 – Exploring the EnvironmentApple’s Container CLI is compatible with Docker CLI. It supports most of the commands and switches with which you are familiar.Let’s run a web server to explore this.container run --name apache -it --rm -d httpdWe can now check the running container with the following command:container lsNotice that there are two fundamental differences between Apple Containers and Docker. We didn’t have to do port mapping by mentioning the container port and host port while running the image. Second, when we listed the containers, we saw that it got a dedicated IP address (192.168.4.2). This indicates that the container is running in a dedicated VM associated with an explicit IP address.Let’s access the container with the curl command.It’s also important to understand that Apple Containers support running the standard OCI images from any public registry. In our case, we pulled the Apache web server from the Docker library.Apple Container environment includes an embedded DNS service that simplifies access to the containerized applications. For example, we can configure dev.local as the DNS domain, making it available to all containers.sudo container system dns create dev.localcontainer system dns default set dev.localNow, when we run a web application, we can access it through container-name.dev.localcontainer run --name nginx -it --rm -d nginxWe can now access the Nginx container using its DNS name – nginx.dev.localStep 3 – Dealing With ImagesYou can follow the familiar workflow of creating a Dockerfile, pushing it to a registry, pulling it, and running it. Let’s see this in action.We will start by building an image from a Python base image.Let’s build the image from the Dockerfile.container build --tag python-test --file Dockerfile .You can list the image by running the command container images ls.Let’s push the image to the Docker image registry. Run the command below to authenticate with your Docker credentials.container registry login docker.ioWe are now ready to tag and push the image.container images tag python-test janakiramm/python-testcontainer push janakiramm/python-testHope you found this tutorial useful. You can continue to explore Apple Containers at https://apple.github.io/container/documentation/.The post Tutorial: Setting Up and Exploring Apple Containerization on macOS appeared first on The New Stack.