env.dev

DOCKER_HOST

Specifies the Docker daemon socket to connect to. Defaults to unix:///var/run/docker.sock on Linux and macOS. Override to connect to a remote Docker daemon over TCP or to use a custom socket path for rootless Docker.

Last updated:

DOCKER_HOST tells the Docker CLI which daemon to talk to. By default it is the local Unix socket unix:///var/run/docker.sock; set it to a tcp:// or ssh:// address to drive a remote daemon, or to a rootless/Docker Desktop/Colima socket path. It is the lever behind a lot of 'Cannot connect to the Docker daemon' errors: if DOCKER_HOST points at a daemon that is not running (or the socket path is wrong for your setup), every docker command fails before doing anything. Testcontainers, CI runners, and IDE integrations all consult it.

Provider
Docker
Category
daemon
Set by
Set via environment variable or Docker context configuration
Default
unix:///var/run/docker.sock
Example
tcp://192.168.1.100:2376
Security: Exposing the daemon over plain tcp:// (port 2375) is effectively remote root on the host — anyone who can reach it can mount the filesystem and escape to the host. Use ssh:// or tcp:// with TLS (DOCKER_TLS_VERIFY=1 and DOCKER_CERT_PATH) for remote daemons, never the unencrypted port.
Gotcha: DOCKER_HOST overrides your active `docker context`. If you switch contexts with `docker context use` but still have a stale DOCKER_HOST exported, the env var wins and you silently talk to the old daemon. On rootless Docker, Colima, or Docker Desktop the socket lives somewhere non-standard (often under $XDG_RUNTIME_DIR or ~/.docker/run) — that mismatch is the usual cause of 'permission denied' or 'no such file' on the socket.

How to set DOCKER_HOST

remote daemon over SSH

export DOCKER_HOST=ssh://user@build-server
docker ps

remote daemon with TLS

export DOCKER_HOST=tcp://192.168.1.100:2376
export DOCKER_TLS_VERIFY=1
export DOCKER_CERT_PATH=~/.docker/certs

back to the local socket

unset DOCKER_HOST   # or: docker context use default

Frequently Asked Questions

Why do I get 'Cannot connect to the Docker daemon at unix:///var/run/docker.sock'?

Either the daemon is not running, or DOCKER_HOST/your docker context points at the wrong socket. Start Docker, then check `echo $DOCKER_HOST` and `docker context ls`. On rootless Docker, Colima, or Docker Desktop the socket is not at the default path, so an exported DOCKER_HOST may be needed — or a stale one may be the problem.

Was this helpful?

Stay up to date

Get notified about new guides, tools, and cheatsheets.

Browse all 242 environment variables →