Support SSH protocol for communication with Docker daemon for image building
Issue
bootBuildImage does not seem to support ssh protocol in DOCKER_HOST
How to reproduce this issue?
Run
DOCKER_HOST="ssh://[email protected]" ./gradlew bootBuildImage
What is expected outcome? Buildpacks build image into the remote machine
What is the current outcome?
➜ DOCKER_HOST="ssh://[email protected]" ./gradlew bootBuildImage
> Task :webservice:bootBuildImage FAILED
Building image 'docker.io/library/webservice:0.0.1-SNAPSHOT'
> Pulling builder image 'docker.io/paketobuildpacks/builder:base' ..................................................
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':webservice:bootBuildImage'.
> Connection to the Docker daemon at '[email protected]' failed with error "[email protected]: Name or service not known"; ensure the Docker daemon is running and accessible
More information Remote daemon works just fine
✗ DOCKER_HOST="ssh://[email protected]" docker info
Client:
Debug Mode: false
Server:
Containers: 8
Running: 4
Paused: 0
Stopped: 4
Images: 44
Server Version: 19.03.13
Storage Driver: overlay2
....
Spring Boot: 2.4.0
You are correct @ruXlab, the SSH protocol is not currently supported for communicating with a Docker host using the Gradle or Maven plugin. When a URL is provided by DOCKER_HOST only the host and port fields of the address are used, and the transport is always assumed to be TCP.
Supporting SSH requires an additional layer on top of the TCP transport as well as some additional configuration to provide a private authentication key. We can consider adding this support in a future Spring Boot release.
The following workaround can be used to build with remote docker over SSH:
Open connection to remote server forwarding a unix sock:
ssh dockervm -L$HOME/remote-docker.sock:/var/run/docker.sock
Run the build:
DOCKER_HOST=unix://$HOME/remote-docker.sock mvn spring-boot:build-image
@weltonrodrigo , thank you for the workaround! Is there a way to do the same on Windows?
@scottfrederick , is this feature is still planned to be done? Meanwhile, it seems sensible to note the absence of SSH support in Spring Boot Gradle Plugin documentation because it was quite frustrating for me to make everything work with SSH but finally find out that the plugin doesn't support this configuration.
@weltonrodrigo , thank you for the workaround! Is there a way to do the same on Windows?
I have no idea. Maybe in WSL the same will work.