Skip to content

docker do not honor custom ssh port in ADD instruction while cloning git repositories #2468

Open

Description

Description

I'm self-hosting git server. It only allows cloning repos via ssh. I've change default ssh port.
I'm trying to use ADD instruction to add my repository to docker image, but it seems that docker doesn't honor other ssh port.

FROM ubuntu:20.04
WORKDIR /project
ADD --keep-git-dir=false ssh://git@example.com:12345/org/project.git /project

Reproduce

docker build --ssh default --tag bug/reproduce:latest -f Dockerfile .
 > [3/3] ADD --keep-git-dir=false ssh://git@example.com:12345/org/project.git /project
0.024 Initialized empty Git repository in /var/lib/docker/overlay2/72yquf1x6jb9lb8xkgjtaol2k/diff/
0.355 Host key verification failed.
0.357 fatal: Could not read from remote repository.
0.357 
0.357 Please make sure you have the correct access rights
0.357 and the repository exists.

Expected behavior

I expect docker to honor custom ports.

docker version

Client: Docker Engine - Community
 Version:           26.1.2
 API version:       1.45
 Go version:        go1.21.10
 Git commit:        211e74b
 Built:             Wed May  8 13:59:59 2024
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          26.1.2
  API version:      1.45 (minimum version 1.24)
  Go version:       go1.21.10
  Git commit:       ef1912d
  Built:            Wed May  8 13:59:59 2024
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.31
  GitCommit:        e377cd56a71523140ca6ae87e30244719194a521
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e94
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

docker info

Client: Docker Engine - Community
 Version:    26.1.2
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.14.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 12
  Running: 0
  Paused: 0
  Stopped: 12
 Images: 26
 Server Version: 26.1.2
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 nvidia runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: e377cd56a71523140ca6ae87e30244719194a521
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.0-28-generic
 Operating System: Ubuntu 22.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.4GiB
 Name: oleksandr-ROG-Zephyrus-M15-GU502LW
 ID: f5e63e23-3a08-4d37-92a3-a76cb7aeb399
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Additional Info

Workaround: modifying ~/.ssh/config file with

Host example.com
    HostName example.com
    Port 12345

works, but this requires to modify ssh/config on every machine that may need to build this image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions