Two ways to create a Docker image. In this guide, we’re going to look at two methods for creating a new Docker image: Create a Docker image from an existing container: In this case, you start with an existing image, customize it with the changes you want, then build a new image from it. Use a Dockerfile: In this case, you use a file of. The GitLab Docker images are monolithic images of GitLab running all the necessary services in a single container. If you instead want to install GitLab on Kubernetes, see GitLab Helm Charts. Find the GitLab official Docker image at: GitLab Docker image in Docker Hub. The Docker images don’t include a mail transport agent (MTA).
Estimated reading time: 4 minutes
Welcome! We are excited that you want to learn Docker.
This page contains step-by-step instructions on how to get started with Docker. In this tutorial, you’ll learn how to:
In addition, you’ll also learn about the best practices for building images, including instructions on how to scan your images for security vulnerabilities.
If you are looking for information on how to containerize an application using your favorite language, see Language-specific getting started guides.
We also recommend the video walkthrough from DockerCon 2020.
This tutorial assumes you have a current version of Docker installed on yourmachine. If you do not have Docker installed, choose your preferred operating system below to download Docker:
For Docker Desktop installation instructions, see Install Docker Desktop on Mac and Install Docker Desktop on Windows.
If you’ve already run the command to get started with the tutorial, congratulations! If not, open a command prompt or bash window, and run the command:
You’ll notice a few flags being used. Here’s some more info on them:
-d- run the container in detached mode (in the background)
-p 80:80- map port 80 of the host to port 80 in the container
docker/getting-started- the image to use
You can combine single character flags to shorten the full command.As an example, the command above could be written as:
Before going too far, we want to highlight the Docker Dashboard, which givesyou a quick view of the containers running on your machine. The Docker Dashboard is available for Mac and Windows. It gives you quick access to container logs, lets you get a shell inside the container, and lets youeasily manage container lifecycle (stop, remove, etc.).
To access the dashboard, follow the instructions in theDocker Desktop manual. If you open the dashboardnow, you will see this tutorial running! The container name (
jolly_bouman below) is arandomly created name. So, you’ll most likely have a different name.
Now that you’ve run a container, what is a container? Simply put, a container issimply another process on your machine that has been isolated from all other processeson the host machine. That isolation leverages kernel namespaces and cgroups, features that have been in Linux for a long time. Docker has worked to make these capabilities approachable and easy to use.
Creating containers from scratch
If you’d like to see how containers are built from scratch, Liz Rice from Aqua Securityhas a fantastic talk in which she creates a container from scratch in Go. While she makesa simple container, this talk doesn’t go into networking, using images for the filesystem, and more. But, it gives a fantastic deep dive into how things are working.
When running a container, it uses an isolated filesystem. This custom filesystem is provided by a container image. Since the image contains the container’s filesystem, it must contain everything needed to run an application - all dependencies, configuration, scripts, binaries, etc. The image also contains other configuration for the container, such as environment variables,a default command to run, and other metadata.
We’ll dive deeper into images later on, covering topics such as layering, best practices, and more.
If you’re familiar with
chroot, think of a container as an extended version of
chroot. Thefilesystem is simply coming from the image. But, a container adds additional isolation notavailable when simply using chroot.
Refer to the following topics for further documentation on all CLI commands used in this article:get started, setup, orientation, quickstart, intro, concepts, containers, docker desktop-->
In some cases, the prebuilt Docker images for model inference and extensibility solutions for Azure Machine Learning may not meet your inference service needs.
In this case, you can use a Dockerfile to create a new image, using one of the prebuilt images as the starting point. By extending from an existing prebuilt Docker image, you can use the Azure Machine Learning network stack and libraries without creating an image from scratch.
Benefits and tradeoffs
Using a Dockerfile allows for full customization of the image before deployment. It allows you to have maximum control over what dependencies or environment variables, among other things, are set in the container.
The main tradeoff for this approach is that an extra image build will take place during deployment, which slows down the deployment process. If you can use the Python package extensibility method, deployment will be faster.
An Azure Machine Learning workspace. For a tutorial on creating a workspace, see Get started with Azure Machine Learning.
Familiarity with authoring a Dockerfile.
Either a local working installation of Docker, including the
docker CLI, OR an Azure Container Registry (ACR) associated with your Azure Machine Learning workspace.
The Azure Container Registry for your workspace is created the first time you train or deploy a model using the workspace. If you've created a new workspace, but not trained or created a model, no Azure Container Registry will exist for the workspace.
Below is a sample Dockerfile that uses an Azure Machine Learning prebuilt Docker image as a base image:
Then put the above Dockerfile into the directory with all the necessary files and run the following command to build the image:
More details about
docker build can be found here in the Docker documentation.
docker build command isn't available locally, use the Azure Container Registry ACR for your Azure Machine Learning Workspace to build the Docker image in the cloud. For more information, see Tutorial: Build and deploy container images with Azure Container Registry.
Microsoft recommends that you first validate that your Dockerfile works locally before trying to create a custom base image via Azure Container Registry.
The following sections contain more specific details on the Dockerfile.
If there are any other
apt packages that need to be installed in the Ubuntu container, you can add them in the Dockerfile. The following example demonstrates how to use the
apt-get command from a Dockerfile:
You can also install addition pip packages from a Dockerfile. The following example demonstrates using
If the model and code need to be built into the image, the following environment variables need to be set in the Dockerfile:
AZUREML_ENTRY_SCRIPT: The entry script of your code. This file contains the
AZUREML_MODEL_DIR: The directory that contains the model file(s). The entry script should use this directory as the root directory of the model.
The following example demonstrates setting these environment variables in the Dockerfile:
The following example demonstrates installing
apt packages, setting environment variables, and including code and models as part of the Dockerfile:
To use a Dockerfile with the Azure Machine Learning Python SDK, see the following documents:
To learn more about deploying a model, see How to deploy a model.
To learn how to troubleshoot prebuilt docker image deployments, see how to troubleshoot prebuilt Docker image deployments.