Docker Community Forums

Share and learn in the Docker community.

Docker exec using TCP via SSH tunnel behaves differently than SSH

I’m using Docker compose to spin up an integration test environment of a PHP application, database, etc. Then I execute the tests in the container of my PHP application. I use DOCKER_HOST=ssh://test.server to run the tests remote (from my Mac).

On my Mac I run

DOCKER_HOST=ssh://test.server docker-compose up -d
DOCKER_HOST=ssh://test.server docker exec php-container \
    ./phpunit --configuration config.xml

This is working fine, but slower than a SSH tunnel as suggested by @mottati in this comment. Therefore, I run

  1. on my Mac
    ssh -L 8888:localhost:8888 test.server
    
  2. on test.server
    socat TCP-LISTEN:8888,reuseaddr,fork UNIX-CONNECT:/var/run/docker.sock
    
  3. on my Mac
    DOCKER_HOST=tcp://localhost:8888 docker-compose up -d
    DOCKER_HOST=tcp://localhost:8888 docker exec php-container \
        ./phpunit --configuration config.xml
    

However, while

DOCKER_HOST=ssh://test.server docker exec php-container \
    ./phpunit --configuration config.xml

is running the tests fine and shows the output,

DOCKER_HOST=tcp://localhost:8888 docker exec php-container \
    ./phpunit --configuration config.xml

terminates immediately without any output and exit code 0 (according to echo $? run directly afterwards). Any idea what might cause this issue or how to analyze it?


Notes:

  • The output of
    DOCKER_HOST=tcp://localhost:8888 docker exec php-container \
        ./phpunit --version
    
    and
    DOCKER_HOST=tcp://localhost:8888 docker exec php-container \
        ./phpunit ./some-test-directory
    
    is shown. It looks like I only can’t run those tests that access the database or do something else that not all tests do. If I exec ps in the container, I see that the phpunit processes never terminate. But what does that all have to do with DOCKER_HOST being tcp://localhost:8888 and not ssh://test.server?

Versions

Mac

  • Docker version 20.10.7
  • docker-compose version 1.29.2, build 5becea4c
  • OpenSSH_8.1p1, LibreSSL 2.7.3

test.server

  • Docker version 20.10.7
  • OpenSSH_8.2p1 Ubuntu-4ubuntu0.2, OpenSSL 1.1.1f 31 Mar 2020
  • socat version 1.7.3.3 on Oct 26 2019 17:42:04

PHP application/container:

  • Docker Image php:7.3-apache
  • PHPUnit 4.8.36 by Sebastian Bergmann and contributors.
1 Like

I figured out, where PHPUnit exits. A data provider tries to access the database using the query method of PDO and just exits. The same thing happen if I call the same SQL query

SELECT COUNT(*) FROM tablename

in a php script instead of running PHPUnit. Shouldn’t the PHP process exit with a non-zero exit code in such case?