Open aduzsardi opened 4 years ago
This use-case will be addressed by https://github.com/docker/cli/pull/2500 (which will be in the upcoming 20.x release of docker)
that said; performance of docker context ls
is on our radar (given that it's a local action, it shouldn't have to depend on the connection-speed with the currently selected context).
Let me move this ticket to the docker/cli issue tracker for visibility.
Currently if you select a context and the connection with the docker host is down , the commands just hang , will this also be addressed ? Thank you
Currently if you select a context and the connection with the docker host is down , the commands just hang , will this also be addressed ?
@aduzsardi docker 19.03.12 was released with some improvements (from https://github.com/docker/cli/pull/2424 and https://github.com/docker/cli/pull/2515). Not sure from the top of my head if those resolve the full issue, but you could give 19.03.12 a spin to see if it performs better
thank you for the notice , updated docker on my system but i don't see any changes for my use cases
aduzsardi@aduzsardi-nix: ~
└─$ ▶ time __docker_ps1
[dctx: bb-dev]
real 0m3.928s
user 0m0.024s
sys 0m0.015s
keeping in mind that i go through a few routers and a VPN from one country to another to reach my remote docker host
also if i disconnect the VPN and trying to switch back the docker context to the default , it hangs forever until finally changes it back to default
I am seeing similar on mac os x.
~ via 🐍 3.8.0 took 14s
➜ time docker context ls
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://localhost:6443 (default) swarm
docker context ls 0.10s user 0.03s system 2% cpu 5.073 total
~ via 🐍 3.8.0 took 5s
➜ time docker context ls
NAME TYPE DESCRIPTION DOCKER ENDPOINT KUBERNETES ENDPOINT ORCHESTRATOR
default * moby Current DOCKER_HOST based configuration unix:///var/run/docker.sock https://localhost:6443 (default) swarm
docker context ls 0.09s user 0.04s system 2% cpu 4.616 total
I only have the context that was setup by installing docker desktop However I noticed the performance degradation when setting up a windows docker context in virtual box
Looks related to both https://github.com/docker/cli/issues/1955 and https://github.com/docker/cli/issues/3096 Both of which report the inability to run local commands when using a context that is either invalid or slow performing.
Any updates on this?
i don't see much activity on fixing issues on docker repositories, so probably nothing new about this one either you are better of not using docker contexts
This is still a problem. It'd be nice to include the docker context in my prompt like spaceship does by default but it makes my zsh prompt super slow so I have to turn it off.
@tbenthompson If you're still looking, the current non-default context is listed in ~/.docker/config.json
under .currentContext
. I added current context to my PS1 prompt by sourcing it from this file.
$ time jq -r .currentContext ~/.docker/config.json
swarm-qa
real 0m0.003s
user 0m0.003s
sys 0m0.000s
When the currentContext = default, this item is absent from config.json
I suppose there's no guarantees that this is a stable way to get this information, but it will have to do.
If you have the docker 23.0 CLI installed you should now also be able to use docker context show
to get the currently configured context. That command only shows the name of the configured context, but (intentionally) won't validate if the context's metadata is valid and/or if it's able to connect using the context;
docker context show
default
DOCKER_CONTEXT=nosuchcontext docker context show
nosuchcontext
It follows the same logic as is used to resolve the context to use when running commands, for example, setting a DOCKER_HOST
will disable using the context, and switch back to "default" (with the host configured through DOCKER_HOST
);
DOCKER_CONTEXT=nosuchcontxt DOCKER_HOST=unix://var/run/docker.sock docker context show
default
Expected behavior
Return current used docker context faster
Actual behavior
while using a remote docker host context through a VPN or over the internet, the listing and inspecting of the contexts is very slow
If using the default (local) docker context , everything seems to be ok
Steps to reproduce the behavior
Output of
docker version
:Output of
docker info
:Additional environment details (AWS, VirtualBox, physical, etc.)
I'm connecting to remote docker or docker swarm hosts trough VPNs from home to office network
I want to set my bash prompt to show the docker context currently in use so i know where i am at all times , but the time it takes to return my prompt every time i press the return key on the keyboard takes about ~3s of so it's not usable
The script i was using
$ cat /etc/profile.d/docker_prompt.sh
And PS1 prompt
Proposal
It would be nice if we could read the currently used context from a file or config , so every time you run
docker context use ...
the config would be updated with the "current-context: something" like kubectl does