compose icon indicating copy to clipboard operation
compose copied to clipboard

Exit code 141 returned when using an ssh DOCKER_HOST

Open lucas42 opened this issue 5 years ago • 6 comments

Description of the issue

When running version 1.28.2 of docker-compose using an ssh DOCKER_HOST, execution fails with a 141 exit code before it even connects to the host.

Context information (for bug reports)

I've encountered this on multiple projects and have managed to reproduce using a bare minimum docker-compose.yml.

It works for me on 1.28.0

Output of docker-compose version

docker-compose version 1.28.2, build 67630359
docker-py version: 4.4.1
CPython version: 3.7.9
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Output of docker version

Client: Docker Engine - Community
 Version:           19.03.12
 API version:       1.40
 Go version:        go1.13.10
 Git commit:        48a66213fe
 Built:             Mon Jun 22 15:42:53 2020
 OS/Arch:           linux/amd64
 Experimental:      false

Output of docker-compose config (This is the smallest config I've managed to reproduce the issue with.)

services: {}
version: '3'

Steps to reproduce the issue

  1. cd /tmp
  2. echo "version: '3'" > docker-compose.yml
  3. DOCKER_HOST="ssh://ssh-host" docker-compose pull (where ssh-host is replaced with a valid ssh server's hostname)

Observed result

Command returns immediately with an exit code of 141

The usual SSH authenticity prompt and password prompts are not shown.

Expected result

docker-compose to attempt to establish an ssh connection with the host given, including any necessary prompts from the SSH client.

An exit code of 0

Stacktrace / full error message

Nothing is output by docker-compose. The return status code is 141. The final few lines from strace are:

rt_sigprocmask(SIG_BLOCK, ~[RTMIN RT_1], [], 8) = 0
getpid()                                = 162
gettid()                                = 162
tgkill(162, 162, SIGPIPE)               = 0
rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
--- SIGPIPE {si_signo=SIGPIPE, si_code=SI_TKILL, si_pid=162, si_uid=3434} ---
+++ killed by SIGPIPE +++

(I can post more if that'd be useful)

Additional information

I've been running docker-compose on circleci, which itself runs inside a docker container. I was able to pull the relevant images from dockerhub to reproduce locally.

The following image contains docker-compose 1.28.0 and works for me: circleci/buildpack-deps@sha256:3c09a91c14193f17287c1dfa00fcfdc2cb1d810c10be3b2f16132f1a6d5d50d1

The following image contains docker-compose 1.28.2 and doesn't work for me: circleci/buildpack-deps@sha256:6857fa3db990ab737b0168ab12d2e5d4f31d373c0f54f2d64e3c4e86d24a1287

lucas42 avatar Feb 03 '21 00:02 lucas42

Not sure if it's related to OP's issue, but I had a similar issue with docker-compose and setting DOCKER_HOST=ssh://xxxx, where docker-compose would silently quit with exit code 141.

Turns out it was a firewall rate-limiting configuration on the ssh/tcp port that came default on my docker host. When SSH connections are established rapidly by the same IP, connections are dropped. This would happen if you're using CI scripts that access the docker host via SSH multiple times quickly.

TLDR, on the docker host:

Check if rate limiting is turned on for ssh/tcp:

# ufw status
Status: active

To                         Action      From
--                         ------      ----
22/tcp                     LIMIT       Anywhere

If you see LIMIT, then you have rate-limiting on. To turn it off:

# ufw ssh/tcp allow

Again, not sure if related to OP's issue but took me a lot of hair-pulling to figure this out. Hopefully will help someone out there.

ronalddddd avatar Feb 04 '21 15:02 ronalddddd

I don't think my problem is related to firewalls on the host. That wouldn't change based on the version of docker-compose I'm running. Also, I've tried it with different hosts and encounter the same problem.

lucas42 avatar Feb 04 '21 20:02 lucas42

@lucas42 try executing it with COMPOSE_PARAMIKO_SSH=1.

sl0wik avatar Feb 08 '21 18:02 sl0wik

Yes, that fixes it @sl0wik - thanks. 👍 Any idea why that broke in 1.28.2? Looking at the release notes, COMPOSE_PARAMIKO_SSH was introduced in 1.28.0.

lucas42 avatar Feb 08 '21 18:02 lucas42

Hi! Thank you for raising the issue.

I think the bug is caused by the bad removal of the ssh:// from the host which causes a wrong hostname to be passed to the ssh client (leading 's' or 'h' in the hostname are removed). Sorry for this, it is my mistake.

The new ssh approach was added in 1.28.0 to try and align with the docker cli. We added the COMPOSE_PARAMIKO_SSH to switch back to the old implementation in case bugs are found in the new one.

We are preparing a fix for v1.28.3.

aiordache avatar Feb 09 '21 10:02 aiordache

I don't want to put even more pressure (or maybe I guess do want to a little bit), but this has literally eaten my brains out in the last week and we thought we were doing something wrong because we were using four relatively large docker-compose files (with override). I tried several docker-compose versions, but now I understand I should have tried it on the client-side, not on the server-side.

The issue in my case was related to these four bigger docker-compose files that we deploy with override. It worked slowly and then it would simply interrupt without any specific errors, with the log set at debug level and with verbose on.

When we deployed it in chunks (several combinations - the first one, then the first and the second and so on and so forth) it would work. But all of them never. stop would also not work. Something to do with parsing all that information, I'm not sure what.

Setting COMPOSE_PARAMIKO_SSH solved it instantly.

Thank you though for opening the thread and thank you for fixing this.

lethargosapatheia avatar Feb 11 '21 16:02 lethargosapatheia