tox-docker icon indicating copy to clipboard operation
tox-docker copied to clipboard

DOCKER_HOST is not respected

Open ssbarnea opened this issue 4 years ago • 7 comments

I do have a DOCKER_HOST=ssh://[email protected] which is correctly used by all docker tools, including the docker-py python library. Still, tox-docker does not seem to rely on it and fails to run, thorwin an exception like:

  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/pluggy/callers.py", line 187, in _multicall
    res = hook_impl.function(*args)
  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/tox_docker.py", line 204, in tox_runtest_pre
    docker.images.pull(name, tag=tag or None)
  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/docker/models/images.py", line 446, in pull
    pull_log = self.client.api.pull(
  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/docker/api/image.py", line 430, in pull
    self._raise_for_status(response)
  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/docker/api/client.py", line 270, in _raise_for_status
    raise create_api_error_from_http_exception(e)
  File "/Users/ssbarnea/c/os/git-review/.tox/.tox/lib/python3.9/site-packages/docker/errors.py", line 31, in create_api_error_from_http_exception
    raise cls(e, response=response, explanation=explanation)
docker.errors.ImageNotFound: 404 Client Error for http+docker://ssh/v1.41/images/create?tag=latest&fromImage=gerrit: Not Found ("pull access denied for gerrit, repository does not exist or may require 'docker login': denied: requested access to the resource is denied")

From the same machine doing a docker pull worked without any problems.

# tox.ini
[tox]
requires =
  tox-docker
  # unless paramiko is mentioned, we would get another error
  paramiko

[docker:gerrit]
image = docker.io/gerritcodereview/gerrit:3.3.1

[testenv:int]
docker =
  gerrit
commands = echo yep!

ssbarnea avatar Jan 27 '21 18:01 ssbarnea

It seems that this bug was fixed in v2.0.0a3 pre-release, but that was like more than 6 months ago. Maybe it would make sense to tag a release.

ssbarnea avatar Jan 27 '21 18:01 ssbarnea

Ugh, sorry about that. I meant to cut the release ... many months ago. 2020 caught up with me. Anyway, https://github.com/tox-dev/tox-docker/releases/tag/v2.0.0 is out the door and https://pypi.org/project/tox-docker/2.0.0/ is published. Let me know if this bug still exists on 2.0, but it seems like it shouldn't.

dcrosta avatar Jan 27 '21 23:01 dcrosta

I have a similar issue in the latest 3.0.0 release. In CircleCI (and others) DOCKER_HOST is set to the remote docker:

circleci@e6187b8d02f3:~/project$ echo $DOCKER_HOST
tcp://34.70.249.139:2376

But running tox with tox-docker yields the standard Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?. It would appear that docker.from_env isn't honouring default settings, in our context.

In case it helps, here's the output of my poetry.lock, after a fresh install - with nothing pinned.

circleci@e6187b8d02f3:~/project$ cat poetry.lock |grep docker
name = "docker"
name = "tox-docker"
description = "Launch a docker instance around test runs"
docker = ">=2.3.0,<5.0"
docker = [
    {file = "docker-4.4.4-py2.py3-none-any.whl", hash = "sha256:f3607d5695be025fa405a12aca2e5df702a57db63790c73b927eb6a94aac60af"},
    {file = "docker-4.4.4.tar.gz", hash = "sha256:d3393c878f575d3a9ca3b94471a3c89a6d960b35feb92f033c0de36cc9d934db"},
tox-docker = [
    {file = "tox-docker-3.0.0.tar.gz", hash = "sha256:ed5bd518bdb8af818164bec6afb71cc5e196a78ca8f47162d83a36d183db3354"},
    {file = "tox_docker-3.0.0-py2.py3-none-any.whl", hash = "sha256:f7a17a1d89f61a4f47baf7ecfd9449ca7f510d1dd3e70ce9861025b71b907671"},

It goes without saying that docker ps runs properly.

chayim avatar May 27 '21 06:05 chayim

This happens with 2.0.0 as well.

chayim avatar May 27 '21 07:05 chayim

How are you running tox?

dcrosta avatar Jun 06 '21 11:06 dcrosta

Standard command line run (tox -e ) via a virtualenv.

chayim avatar Jun 06 '21 13:06 chayim

I wonder if something is preventing the env var from getting through. DOCKER_HOST should work as expected. Could you try using passenv or setenv in your tox.ini, let me know if that works? Or add something like action.setactivity("docker", f"env is {os.environ}") into about here: https://github.com/tox-dev/tox-docker/blob/master/tox_docker/init.py#L243

dcrosta avatar Jun 06 '21 15:06 dcrosta