Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"no container found" error with docker-compose 2.2 #27

Open
remi-dupre opened this issue Dec 2, 2021 · 0 comments
Open

"no container found" error with docker-compose 2.2 #27

remi-dupre opened this issue Dec 2, 2021 · 0 comments

Comments

@remi-dupre
Copy link

remi-dupre commented Dec 2, 2021

Hello !

I've run into an issue, which I think may be caused by my very recent version of docker-compose (2.2.0).

Minimal reproduction

I created a project in /tmp/foo with following files:

tests/docker-compose.yml

version: "3"
services:
  elasticsearch:
    image: elasticsearch:7.14.2
    ports:
      - "9200"

tests/conftest.py

import pytest

@pytest.fixture(scope='session')
def docker_app(docker_services):
    docker_services.start('elasticsearch')
    public_port = docker_services.wait_for_service("elasticsearch", 9200)

tests/test_foo.py

def test_foo(docker_app):
    assert False

Result

pytest fails with the following message:

docker_services = <lovely.pytest.docker.compose.Services object at 0x7fed40b556d0>

    @pytest.fixture(scope='session')
    def docker_app(docker_services):
        docker_services.start('elasticsearch')
>       public_port = docker_services.wait_for_service("elasticsearch", 9200)

tests/conftest.py:6:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/home/remi/.local/share/virtualenvs/foo-r-OLon9H/lib/python3.9/site-packages/lovely/pytest/docker/compose.py:98: in wait_for_service
    public_port = self.port_for(service, private_port)
/home/remi/.local/share/virtualenvs/foo-r-OLon9H/lib/python3.9/site-packages/lovely/pytest/docker/compose.py:117: in port_for
    output = self._docker_compose.execute(
/home/remi/.local/share/virtualenvs/foo-r-OLon9H/lib/python3.9/site-packages/lovely/pytest/docker/compose.py:166: in execute
    return execute(command)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

command = ['docker-compose', '--project-directory', '/tmp/foo/tests', '-f', '/tmp/foo/tests/docker-compose.yml', '-p', ...], success_codes = (0,)

    def execute(command, success_codes=(0,)):
        """Run a shell command."""
        try:
            output = subprocess.check_output(
                command,
                stderr=subprocess.STDOUT,
                shell=False,
            )
            status = 0
        except subprocess.CalledProcessError as error:
            output = error.output or b''
            status = error.returncode
            command = error.cmd
        output = output.decode('utf-8')
        if status not in success_codes:
>           raise Exception(
                'Command %r returned %d: """%s""".' % (command, status, output)
            )
E           Exception: Command ['docker-compose', '--project-directory', '/tmp/foo/tests', '-f', '/tmp/foo/tests/docker-compose.yml', '-p', 'pytest/tmp/foo', 'port', 'elasticsearch', '9200'] returned 1: """no container found for elasticsearch_1
E           """.

The error seems to simply come from how the project name is defined (-p pytest/tmp/foo) as the slashes should be trimmed. The actual name of the created container is pytesttmpfoo-elasticsearch-1 so the project name should be pytesttmpfoo. The following commands exits normally:

$ docker-compose --project-directory /tmp/foo/tests -f /tmp/foo/tests/docker-compose.yml -p "pytest/tmp/foo" port elasticsearch 9200
no container found for elasticsearch_1

I'm not sure whether this unexpected behavior comes from docker-compose or this project, so I stick with reporting it in an issue even though it seems easy to fix here: https://github.com/lovelysystems/lovely-pytest-docker/blob/master/src/lovely/pytest/docker/compose.py#L210.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant