Docker Context¶
Docker context lets Docker commands on the development host target a remote VeeaHub Docker daemon.
Warning
Docker commands run against the currently selected Docker context. Confirm the active context before running destructive commands.
Show Contexts¶
Run:
On a fresh Docker install, the only context is usually default:
NAME DESCRIPTION DOCKER ENDPOINT
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock
Create a VeeaHub Context¶
First confirm the hub is configured:
Create the context:
Expected output:
Reboot the VeeaHub:
Validate the context:
Expected output:
List contexts again:
The VeeaHub context should appear beside default:
NAME DESCRIPTION DOCKER ENDPOINT
default * Current DOCKER_HOST based configuration unix:///var/run/docker.sock
vh-2341 tcp://192.168.1.36:2376
Use a Default Context¶
Set the active Docker context:
Return to local Docker:
Use a Dynamic Context¶
Prefer dynamic context in examples and scripts:
With the required API version:
This runs only that command against vh-2341. Later commands continue to use the default context.
Expected output for a mesh shows Swarm nodes and the manager:
ID HOSTNAME STATUS AVAILABILITY MANAGER
3ee1vv4eezf33r7q0y0oftskq E09BCW00C0B000000519 Ready Active
nq62rqtirly5r2l6nnglr1nza E09BCWE0C0B000000594 Ready Active
slveb02jifizf4fezib88lioj * E10CTWE080C000002341 Ready Active Leader
Recommended Pattern¶
Use dynamic context for examples, scripts, and destructive commands:
This is more verbose, but it makes the target explicit every time.
Use docker context use <context> only when you are doing a focused interactive session and can see the active context in your prompt.
Optional Prompt Helper¶
If you often switch contexts, add a prompt helper so the active context is visible.
Create ~/docker-escape-prompt:
#!/bin/sh
ctx=$(docker context show)
if [ "$ctx" = "default" ]
then
echo "\033[01;37m[Docker context:${ctx}]"
else
echo "\033[01;31m[Docker context:${ctx}]"
fi
Make it executable:
Add this to ~/.bashrc:
To revert to a normal prompt: