Create a context using the Docker endpoint configuration from another context
In this step, you will learn how to create a new Docker context and explicitly specify the Docker endpoint configuration, potentially using information from another context as a reference. While the previous step showed how to copy an entire context, this method allows for more granular control over the new context's configuration.
First, let's list the existing contexts to see what we have.
docker context ls
You should see default
, my-local-context
, and my-copied-context
.
Now, we will create a new context named my-explicit-context
. We will explicitly define the Docker endpoint using the --docker
flag, similar to Step 1. We can refer to the configuration of an existing context like my-local-context
to get the correct endpoint details, although in this case, it's the standard local socket.
docker context create my-explicit-context --description "Context with explicit local endpoint" --docker "host=unix:///var/run/docker.sock"
We've also added a description using the --description
flag to make the context's purpose clearer.
List the contexts again to see the newly created my-explicit-context
.
docker context ls
You should now see default
, my-local-context
, my-copied-context
, and my-explicit-context
.
Switch to the new context to make it active.
docker context use my-explicit-context
List the contexts one more time to confirm that my-explicit-context
is the active one.
docker context ls
You can also inspect the configuration of my-explicit-context
to see the details, including the description you added.
docker context inspect my-explicit-context
This demonstrates how you can create a context by explicitly providing the Docker endpoint configuration, which is useful when connecting to remote Docker daemons or when you need precise control over the connection details.