compose: [BUG] Can not delete Container over ssh if there is more than one

Description

Trying to “down” a compose over ssh will fail It needs to be two or more services inside the compose (one services works)

Similar issue here : https://github.com/docker/compose/issues/9185

Steps To Reproduce

1: docker-compose.yml

version: '3.8'
services:

  busybox1:
    image: busybox
    command: "sleep 1d"
    
  busybox2:
    image: busybox
    command: "sleep 1d"

2: Run services, then stop

docker-compose -H ssh://USER@remote up -d && docker-compose -H ssh://USER@remote down

3: An error occurs

[+] Running 2/2
 - Container composev2-busybox2-1  Started                                                                            1.2s
 - Container composev2-busybox1-1  Started                                                                            2.8s
[+] Running 1/2
 - Container composev2-busybox2-1  Removed                                                                           10.5s
 - Container composev2-busybox1-1  Error while Removing                                                              11.8s
error during connect: Delete "http://docker/v1.41/containers/9ec831308cba7cd8c68a698c7e1db9985974033918f58def885d18ba9b9059e4?force=1": command [ssh -l USER -- docker-vm docker system dial-stdio] has exited with exit status 1, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=

Compose Version

Docker version 20.10.12, build 20.10.12-0ubuntu4

Docker Compose version v2.14.0

Docker Environment

Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 125
  Running: 6
  Paused: 0
  Stopped: 119
 Images: 90
 Server Version: 20.10.12
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  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 logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.15.0-56-generic
 Operating System: Ubuntu 22.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 30.99GiB
 Name: hugues-tribu
 ID: OLST:TX4F:WU5G:FY2S:6OSC:HPJ6:E33R:UP6P:OAQU:74T7:VPR2:UEBB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (4 by maintainers)

Most upvoted comments

The ssh’s MaxStartups default config value (i.e. allow up to 10 concurrent unauthenticated ssh connections, and then randomly close any extra ones until there are 100 concurrent attempts, at which point hard reject the extra ones) thing should honestly be mentioned in docker compose docs. Everyone starts googling a solution to this problem the moment they have more than 10 docker containers defined in their docker-compose.yml file.

I’m pasting my specific cli error, so that google may index it and the next person looking for it doesn’t spend hours to find it:

unable to get image ‘nginx:1.15-alpine’: error during connect: Get “http://docker.example.com/v1.42/images/nginx:1.15-alpine/json”: command [ssh -o ConnectTimeout=30 -l vagrant – 192.168.33.100 docker system dial-stdio] has exited with exit status 255, please make sure the URL is valid, and Docker 18.09 or later is installed on the remote host: stderr=kex_exchange_identification: read: Connection reset by peer

Docker Compose by nature runs multiple docker API calls concurrently and can indeed quickly reach the ssh limits. Docker ssh support is actually implemented by running docker system dial-stdio on remote host, and doesn’t offer multiplexing so we could have multiple API calls over a single ssh connexion. I don’t expect we get any short terms workaround to this limitation

I’d like to add that the multiplexing trick does not work on Windows since its OpenSSH implementation does not support the feature. Windows users can therefore only resort to the MaxStartups server-side config. I don’t know how Docker Desktop users are doing, but in my case with remote Linux Engines this issue is highly impactful as it consistently breaks multi-container deployments.

Since switching to SSH authentication from certificates (RIP RancherOS), I noticed a substantial slowdown in all docker commands (both direct CLI and compose) including server-side SSH logs like kex_exchange_identification: connection reset by peer. I don’t know if it’s a bug in Windows’ OpenSSH implementation or Docker, but it’s quite an inconvenience.

Is there a Docker-side code change that can resolve the situation? If so, can we expect to find it soon in an upcoming release? (maybe after #11165 is also fixed)

@ndeloof

I reverted the /etc/sshd_config::MaxStartups config change, and enabled ssh multiplexing using the .ssh/config snippet that husjon mentioned, and I can confirm that enabling ssh multiplexing for my “remote” docker machine “ssh hosts” works. As an added bonus: the docker compose up -d seems to run marginally faster – the docker containers reach the “Created” state all-at-once. This is most likely due to not having to go through the same ssh-handshaking over 10 times.

Bottom line is that the PR that you proposed is not only fixing the problem, but also makes things run in a more proper way (because one could argue that “spamming a remote sshd with logins” is not entirely proper due to resemblance to a minor ddos attack).

Have a good day.

@ndeloof I just tried with multiplexing enabled in my ssh config towards one of my docker nodes.

ControlPath ~/.ssh/controlmasters-%r@%h:%p
ControlMaster auto
ControlPersist 10m

Note: compared to the example from ssh multiplexing, I changed the path to ~/.ssh/controlmasters-%r@%h:%p since the example requires the folder to exist before it works.

~I see that the server only receives 1 ssh connection as expected~ ~Correction: it seem like it still receives each connection individually.~

Correction 2: I was too quick to jump to conclusions, I hadn’t switched the context. Using the example compose file below, it seem to work fine using multiplexing.

https://gist.github.com/husjon/0d6aff7e726073dc00259ef39b3d9907#file-docker-compose-yaml