This lab provides an introduction to Docker command line tools and the workflow for using existing (public) Docker images, creating new Docker images, adding new images to a private registry and then deploying the image for use in a standalone environment.
In this section we will leverage https://KataCoda.com and use their interactive exercises.
- Click here and do the following exercises:
Deploying Your First Docker Container
Building Container Images
The purpose of this section is to understand how to build a Container Image from a GitHub Repository (i.e. Application Code) and script a container image build with a Dockerfile
. After your custom image is built you will then push it to your own Private Container Registry (i.e. Azure Container Registry (ACR)).
You will need to create a Dockerfile
in your project.
-
This file is an instruction set that outlines to docker:
- where/what/which base image you will start with
- to which working directory you wish to start with inside your image
- what file(s) to copy into your new container image
- potentially which ports to map to (from your host to your running container)
- any potential commands to run inside your container (i.e. how to boot up your applicaion code)
-
The first step is to build the Container Image.
- To make this easier, we are going to leverage the existing Tutorial in Azure Docs. Click here to navigate to the Docs.
The purpose of this section is to help you understand how to clone/copy images via the PULL (from public image repositories), TAG (update versioning and/or destination registry) and PUSH (to registry) flow with the docker command line tool (aka docker client).
- Once you have an existing Container Image, the next step is to tag and push your Custom Container Image to Private Registry, in our case ACR.
- If you want to try this on your own, the high-level flow will look like the following:
- Create an Azure Container Registry (ACR)
- Pull in a public image from docker hub (e.g.
kevingbb/bobble
) - Re-tag the public image and namespace it to your private registry (hint:
<registry_name>.azurecr.io/<image_name>
)
- If you are a bit gun shy, you can leverage the existing Tutorial in Azure Docs. Click here to navigate to the Docs.
- If you want to try this on your own, the high-level flow will look like the following:
- By default the
docker
command knows topull
from docker hub registry - In order to
push
to your registry you must be logged in by runningdocker login <your-private-repo-url>
docker login
by itself will log you in to docker hub- you must include a URL to authenticate against a privately hosted registry (like Azure Container Registry)
- after logging into your registry, credentials are cached for future use
- for Azure Container Registry your username is the same as
<registry_name>
.azurecr.io - the password can be found in your Azure Container Registry Dashboard in the Azure Portal
- for Azure Container Registry your username is the same as
- You can check your cached credentials in your
.docker/config.json
in your home folder- you will see the registries your're logged into and can
push
to
- you will see the registries your're logged into and can
- By tagging images with
<registry_name>/<image_name>
docker will resolve this name to the proper<registry_name>
to push/pull to- simple names like
kevingbb/<image_name>
are likely docker hub registries - complex names like
<registry_name>.azurecr.io/<image_name>
are privately hosted registries (not docker hub)
- simple names like
- Stop and Start an existing Container.
- Hint: You will need to use the docker cli along with the stop and start commands.
- Create a file inside of an existing running Container.
- Hint: You will need to use the docker cli along with the exec command.
- Create a new Container based on the Container you added the file too.
- Hint: You will need to use the docker cli along with the commit command.