To manage a remote Docker host SSH can be used as a transport. This allows connectivity to a remote docker host without having to expose the Docker daemon directly to the internet. It also does not require any modifications in the standard daemon.json configuration file.
To connect to a remote host a context can be created:
docker context create \
--docker host=ssh://username@hostname.example.com \
--description="My docker remote host" \
my-docker-remote-host
The Docker context can then be switched to the new one:
docker context use my-docker-remote-host
To switch back to local context, go back to the default context:
docker context use default
An alternative to creating a context is setting the DOCKER_HOST environment variable:
export DOCKER_HOST=ssh://user@hostname.example.com
Subsequent commands will then be executed on the remote host.