Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

VS Code's container view cannot reach Docker although Docker works

Your error

Failed to connect. Is Docker installed and running?

Fix it fast

Most common cause, 1 of 2

A DOCKER_HOST value overrides the Docker context that works

Remove the override and let the extension follow the active Docker context, which the guide recommends over a containers.environment entry.

Fix
# shell profile: delete the export line, then
unset DOCKER_HOST

// VS Code settings.json: remove the block
// "containers.environment": { "DOCKER_HOST": "..." }

# a remote engine as a context instead
docker context create --docker host=ssh://docker-user@host1.example.com my-remote-engine
docker context use my-remote-engine
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

Failed to connect. Is Docker installed and running? in VS Code means the Container Tools extension could not reach a Docker engine from where it runs. If docker ps works in a terminal, a DOCKER_HOST value in settings or the environment is overriding your Docker context, or a remote window is checking the remote machine. Applies to Container Tools 2.x.

  • Applies to VS Code Container Tools extension 2.5.3, Docker Desktop 4.100 (macOS and Windows), Docker Engine 29
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run the same checks in VS Code's integrated terminal that the extension relies on. If docker ps fails here and in a normal terminal too, the engine itself is down, which is a separate problem. If it works but DOCKER_HOST is set or the settings carry containers.environment, cause 1 applies. If the window title shows SSH, WSL or Dev Container, cause 2 applies.

Run this first
docker ps
docker context ls
echo "DOCKER_HOST=$DOCKER_HOST"
# then search your VS Code user and workspace settings for containers.environment

Then find the line you see in this list and open its fix:

  1. 1A DOCKER_HOST value overrides the Docker context that worksdocker context ls marks a working context with an asterisk, yet DOCKER_HOST is set in the environment or under containers.environment in VS Code settings
  2. 2A remote window asks the remote machine, which has no reachable DockerThe window is connected over SSH, to WSL or to a dev container, and the error appears even though Docker Desktop runs on your laptop

What does the error look like?

  • Failed to connect. Is Docker installed and running?

Cause 1 of 2

A DOCKER_HOST value overrides the Docker context that works

You seedocker context ls marks a working context with an asterisk, yet DOCKER_HOST is set in the environment or under containers.environment in VS Code settings

Check

VS Code's container troubleshooting guide sets an order: the containers.environment.DOCKER_HOST setting overrides your Docker context, and a DOCKER_HOST environment variable overrides both. A value left over from an old remote host, a VM that is gone, or one written without its ssh:// or tcp:// protocol, which the guide says is required, sends the extension to an engine that does not answer.

Check
env | grep -E '^DOCKER_(HOST|CONTEXT)='

Fix

Remove the override and let the extension follow the active Docker context, which the guide recommends over a containers.environment entry. If you do need a remote engine, create a context for it instead of setting DOCKER_HOST.

Fix
# shell profile: delete the export line, then
unset DOCKER_HOST

// VS Code settings.json: remove the block
// "containers.environment": { "DOCKER_HOST": "..." }

# a remote engine as a context instead
docker context create --docker host=ssh://docker-user@host1.example.com my-remote-engine
docker context use my-remote-engine

Verify

Reload the VS Code window. The Containers view lists your containers and images.

Verify
docker context ls

Confirmed by code.visualstudio.com

Did this fix it?

Cause 2 of 2

A remote window asks the remote machine, which has no reachable Docker

You seeThe window is connected over SSH, to WSL or to a dev container, and the error appears even though Docker Desktop runs on your laptop

Check

In a remote setup the remote machine is where Docker has to work, not your laptop. The troubleshooting guide's answer to this exact message is to confirm that the Docker engine is installed on the remote machine and that docker ps runs there without errors, and to install the extension both locally and remotely.

Check
# in the remote window's integrated terminal
docker ps
docker version

Fix

Install Docker Engine on the remote machine and give your remote user access to it, or open the folder in a local window if you meant to use the local engine. Add the extension to the remote side from the Extensions view.

Fix
# on the remote machine, once Docker Engine is installed
# and your remote user may use the Docker socket
docker ps

Verify

docker ps succeeds in the remote terminal, and after a window reload the Containers view fills in.

Verify
docker ps --format '{{.Names}}'

Confirmed by code.visualstudio.com

Did this fix it?

How do I stop it coming back?

  • Point the CLI at remote engines with named docker contexts instead of a DOCKER_HOST export in your shell profile.
  • Keep containers.environment out of user settings; if a project truly needs it, put it in that workspace's settings so other projects are not affected.
  • Before opening a remote folder that uses containers, run docker ps once in the remote terminal.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: TaxiDex, Dispatch Pro.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.