Skip to content

Commit

Permalink
feat: support the unix: scheme in DOCKER_HOST (#83)
Browse files Browse the repository at this point in the history
In get_docker_ip(), if `DOCKER_HOST` is using the `unix:` scheme then
return "127.0.0.1"
  • Loading branch information
JohnVillalovos committed Jul 22, 2022
1 parent 567fa09 commit d3536b3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/pytest_docker/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_docker_ip():
# 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:
if not docker_host or docker_host.startswith("unix://"):
return "127.0.0.1"

match = re.match(r"^tcp://(.+?):\d+$", docker_host)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_docker_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ def test_docker_ip_remote():
assert get_docker_ip() == "1.2.3.4"


def test_docker_ip_unix():
environ = {"DOCKER_HOST": "unix:///run/user/1000/podman/podman.sock"}
with mock.patch("os.environ", environ):
assert get_docker_ip() == "127.0.0.1"


@pytest.mark.parametrize("docker_host", ["http://1.2.3.4:2376"])
def test_docker_ip_remote_invalid(docker_host):
environ = {"DOCKER_HOST": docker_host}
Expand Down

0 comments on commit d3536b3

Please sign in to comment.