tox-dev / tox-docker

A tox plugin to run one or more Docker containers during tests

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hostname container not taken into account

cmarmo opened this issue · comments

Dear maintainers,

first of all, thanks for developing this tox plugin, it really made my life easier!

I believe I have stumbled upon an issue trying to define the hostname of the container via an environment variable.
It looks like the environment variable is not taken into account.

In order to reproduce this behavior I have created an empty project with a tox.ini as follows

[tox]
envlist =
    py311

[docker:gitlab]
image = gitlab/gitlab-ce:latest
host_var = GITLAB_HOST
environment =
    GITLAB_HOST=gitlab

[testenv]
docker =
    gitlab

commands =
    python -c "print('Hello Docker')"

Running

tox --docker-dont-stop=gitlab

generates a container which I am inspecting with

$ docker inspect <container_name> | grep Hostname
            "HostnamePath": "/var/lib/docker/containers/7fa59b2cbdcd4c2f99674ff5d5820ae5dc7041936e4ac93ceaf57e2ec31d5a35/hostname",
            "Hostname": "7fa59b2cbdcd",

I was expecting to see "Hostname": "gitlab".

Is this the expected behavior? In that case how can I set a specific hostname for the container?

If this is not the expected behavior I can offer a pull request to fix the issue.

Thank you for your attention.

I think this may be a documentation clarification, but it seems that everything is working as expected, from what I can see. The host_var configuration is not meant to set the hostname on the container; what it does is define the name of a variable which will be set in the testenv, whose value is the hostname or IP of the container; this is to enable your test code (which does not run in the container) to address services the container offers.

Understood! Thanks for clarifying and sorry for the noise.

I will try to solve my issue (setting the hostname) in a different way then.
Closing this one. Thanks!