WSL Docker mystery environment

I have weird Heisenbug-like experience where sometimes docker on WSL references the same containers, images, etc as Docker Desktop, and sometimes it references some other environment that’s completely invisible to Docker Desktop. Which environment is referenced seems to change after a reboot but I’m not 100% sure of the conditions that trigger the change. Is it normal to expect these divergent environments between WSL and Windows, and how can I control which environment is selected?

Have you checked docker context ls? The currently used context should be marked with a * character. The context should not change on its own.

Switching to either Linux or Windows containers will switch the engine:
image

Terminal commands can be used to switch the context:

Furthermore, the environment variable DOCKER_CONTEXT can be used to set a context, or DOCKER_HOST can be used to override the target docker engine (in case the default context is used).

1 Like