docker_ip fails if DOCKER_HOST is set to the unix socket
thomasleveil opened this issue · 2 comments
thomasleveil commented
In my CI environment (Gitlab CI), the whole pipeline runs in a docker container which pilot the host system docker engine thought a unix socket mounted as a volume. As a consequence, the environment in which pytest is run has the DOCKER_HOST
variable set to unix:///var/run/docker.sock
.
And when running pytest, the docker_ip
fixture fails with:
@pytest.fixture(scope='session')
def docker_ip():
"""Determine IP address for TCP connections to Docker containers."""
# When talking to the Docker daemon via a UNIX socket, route all TCP
# traffic to docker containers via the TCP loopback interface.
docker_host = os.environ.get('DOCKER_HOST', '').strip()
if not docker_host:
return '127.0.0.1'
match = re.match('^tcp://(.+?):\d+$', docker_host)
if not match:
> raise ValueError(
'Invalid value for DOCKER_HOST: "%s".' % (docker_host,)
)
E ValueError: Invalid value for DOCKER_HOST: "unix:///var/run/docker.sock".
/usr/lib/python3.8/site-packages/lovely/pytest/docker/compose.py:173: ValueError
dobe commented
you can override the docker_ip fixture in your conftest
dobe commented
closing this ticket, since there is a workaround, and there are no tests using a socket. feel free to re-open if there is need for it.