container by building, running, and publishing a simple web server image.
Try out the container CLI
Start the application and try out some basic commands to familiarize yourself with the command line interface (CLI) tool.Start the container service
Start the services that If you have not installed a Linux kernel yet, the command will prompt you to install one:
container uses:Verify the installation
Verify that the application is working by running a command to list all containers:If you haven’t created any containers yet, the command outputs an empty list:
Set up a local DNS domain (optional)
container includes an embedded DNS service that simplifies access to your containerized applications. If you want to configure a local DNS domain named test for this tutorial, run:/etc/resolver directory.The second command makes
test the default domain to use when running a container with an unqualified name. For example, if the default domain is test and you use --name my-web-server to start a container, queries to my-web-server.test will respond with that container’s IP address.Build an image
Set up aDockerfile for a basic Python web server, and use it to build a container image named web-test.
Set up a simple project
Start a terminal and create a directory named In the
web-test for the files needed to create the container image:web-test directory, create a file named Dockerfile with this content:The
FROM line instructs the container builder to start with a base image containing the latest production version of Python 3.The WORKDIR line creates a directory /content in the image and makes it the current directory.The first RUN line adds the curl command to your image, and the second RUN line creates a simple HTML landing page.The CMD line configures the container to run a simple web server in Python on port 80.Build the web server image
Run the The last argument
container build command to create an image with the name web-test from your Dockerfile:. tells the builder to use the current directory (web-test) as the root of the build context. You can copy files within the build context into your image using the COPY command in your Dockerfile.After the build completes, list the images. You should see both the base image and the image that you built in the results:Run containers
Using your container image, run a web server and try out different ways of interacting with it.Start the webserver
Use The Open the website using the container’s IP address in the URL:If you configured the local domain
container run to start a container named my-web-server that runs your webserver:--detach flag runs the container in the background, so that you can continue running commands in the same terminal. The --rm flag causes the container to be removed automatically after it stops.When you list containers now, my-web-server is present, along with the container that container started to build your image:test earlier, you can also open the page with the full hostname:Monitor container resource usage
Now that your web server is running, you can monitor its resource usage with the This displays real-time statistics about CPU usage, memory consumption, network traffic, disk I/O, and the number of running processes:
container stats command:Without the
--no-stream flag, container stats continuously updates the display in real-time, similar to the top command. Press Ctrl+C to exit the live view.Run other commands in the container
You can run other commands in If you want to poke around in the container, run a shell and issue one or more commands:
my-web-server by using the container exec command. To list the files under the content directory, run an ls command:The
--tty and --interactive flags allow you to interact with the shell from your host terminal. You will often see these two options abbreviated and specified together as -ti or -it.Access the web server from another container
Your web server is accessible from other containers as well as from your host. Launch a second container using your The output should appear as:If you set up the
web-test image, and this time, specify a curl command to retrieve the index.html content from the first container.Container relies on new features present in macOS 26. As a result, the functionality of accessing the web server from another container will not work on macOS 15. See the technical overview for more details.
test domain earlier, you can achieve the same result with:Publish your image
Push your image to a container registry, publishing it so that you and others can use it.Log in to a registry
To publish your image, you need to push images to a registry service that stores the image for future use. Typically, you need to authenticate with a registry to push an image.To sign into a secure registry with your login credentials, enter your username and password at the prompts after running:
This example assumes that you have an account at a hypothetical registry named
some-registry.example.com with username fido and a password or token my-secret, and that your personal repository name is the same as your username.Tag your image
Create another name for your image that includes the registry name, your repository name, and the image name, with the tag
latest:Push the image
Then, push the image:
By default
container is configured to use Docker Hub. You can change the default registry to another value by running container system property set registry.domain some-registry.example.com.