Create a new Docker context
In this step, we will create a new Docker context. While we won't be connecting to a remote daemon in this lab, creating a context is a fundamental skill. We will create a context that points to the same local Docker daemon as the default context, but with a different name. This will help us understand the process of creating and switching contexts.
To create a new Docker context, you use the docker context create
command followed by the name you want to give the new context. You also need to specify the endpoint for the Docker daemon. For this example, we will create a context named my-local-context
that points to the local Docker daemon using the Unix socket /var/run/docker.sock
.
Let's create the new context:
docker context create my-local-context --docker "host=unix:///var/run/docker.sock"
You should see output confirming the creation of the context:
my-local-context
Successfully created context "my-local-context"
Now, let's list the contexts again to see the newly created one.
docker context ls
The output will now show both the default
context and your new my-local-context
.
NAME DESCRIPTION DOCKER ENDPOINT ORCHESTRATOR
default * Current DOCKER_HOST environment unix:///var/run/docker.sock swarm
my-local-context unix:///var/run/docker.sock
Notice that the default
context is still marked with an asterisk (*), indicating it is the currently active context.