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

docker-compose - The domain name was not added to hosts file #32

Open
FDiskas opened this issue Aug 29, 2016 · 9 comments · May be fixed by #34
Open

docker-compose - The domain name was not added to hosts file #32

FDiskas opened this issue Aug 29, 2016 · 9 comments · May be fixed by #34

Comments

@FDiskas
Copy link

FDiskas commented Aug 29, 2016

The domain name was not added to hosts file
I'm using docker-compose syntax version 2.

version: '2'
services:
    web:
        container_name: test
        build:
            context: .docker
        volumes:
            - .:/var/www/html
        environment:
            DOMAIN_NAME: "dynamic-ads.dev,www.dynamic-ads.dev"
        ports:
            - 80:80
docker inspect test
"Env": [
                "DOMAIN_NAME=dynamic-ads.dev,www.dynamic-ads.dev",
                "affinity:container==0a8de1646a1a4903bc771f17589bc341762b3750a2d7f54767e4d383fd1c6b44",
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "PHPIZE_DEPS=autoconf \t\tfile \t\tg++ \t\tgcc \t\tlibc-dev \t\tmake \t\tpkg-config \t\tre2c",
                "PHP_INI_DIR=/usr/local/etc/php",
                "APACHE_CONFDIR=/etc/apache2",
                "APACHE_ENVVARS=/etc/apache2/envvars",
                "PHP_EXTRA_BUILD_DEPS=apache2-dev",
                "PHP_EXTRA_CONFIGURE_ARGS=--with-apxs2",
                "GPG_KEYS=0BD78B5F97500D450838F95DFE857D9A90D90EC1 6E4F6AB321FDC07F2C332E3AC2BF0BC433CFC8B3",
                "PHP_VERSION=5.6.24",
                "PHP_FILENAME=php-5.6.24.tar.xz",
                "PHP_SHA256=ed7c38c6dac539ade62e08118258f4dac0c49beca04d8603bee4e0ea6ca8250b",
                "COMPOSER_HOME=/var/www/.composer"
            ],

but /etc/hosts file looks like

## docker-hostmanager-start
172.19.0.5 web.testdevelopment_default 2b977a71515b.testdevelopment_default test.testdevelopment_default
## docker-hostmanager-end
$ docker info
Containers: 10
 Running: 5
 Paused: 0
 Stopped: 5
Images: 80
Server Version: 1.12.1
Storage Driver: devicemapper
 Pool Name: docker-253:0-2503770-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 107.4 GB
 Backing Filesystem: xfs
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 6.629 GB
 Data Space Total: 107.4 GB
 Data Space Available: 22.77 GB
 Metadata Space Used: 13.07 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.134 GB
 Thin Pool Minimum Free Space: 10.74 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.122 (2016-04-09)
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: overlay bridge null host
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Security Options: seccomp
Kernel Version: 4.6.7-300.fc24.x86_64
Operating System: Fedora 24 (Workstation Edition)
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.4 GiB
Name: 169.v14.nfq.lt
ID: I5UY:L2HD:OL4R:CV33:B62G:GISP:BWVG:W3QX:AZ77:MFWA:CTKR:IVHO
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Insecure Registries:
 127.0.0.0/8
@FDiskas FDiskas changed the title docker-compose docker-compose - The domain name was not added to hosts file Aug 29, 2016
@aistis-
Copy link

aistis- commented Aug 30, 2016

I confirm it is an issue for docker-compose v2

@iamluc
Copy link
Owner

iamluc commented Aug 30, 2016

If I remember well, the problem is that with v2, a container has 1 IP by network and can be in several networks. But we can only register 1 IP by domain name.

Nevertheless, It should be possible to extend domain name declaration, or to use the domain name when the container is connected to only 1 network.

@FDiskas
Copy link
Author

FDiskas commented Sep 1, 2016

Yes please fiix this.

Jean-Beru added a commit to Jean-Beru/docker-hostmanager that referenced this issue Oct 31, 2016
Jean-Beru added a commit to Jean-Beru/docker-hostmanager that referenced this issue Oct 31, 2016
@Jean-Beru Jean-Beru linked a pull request Oct 31, 2016 that will close this issue
@bernhardberger
Copy link

any news on this? imho with v2 and v3 this is badly needed

@bernhardberger
Copy link

I experimented a bit for my local dev environment and came to the following solution:

Synchronizer.php:

if (isset($container['Config']['Labels']['tld.mycompany.docker-hostmanager.network.' . $networkName . '.vhost'])) {
                    $hosts[] = $container['Config']['Labels']['tld.mycompany.docker-hostmanager.network.' . $networkName . '.vhost'];
                }

and in docker-compose.yml:

services:
   web:
     - tld.mycompany.docker-hostmanager.network.${COMPOSE_PROJECT_NAME}_default.vhost=my-virtual-domain.tld

This way I can match my hosts entry to specific networks (or in this case the default network). I won't do a pull request though as it compromises your DOMAIN_NAME compatibility requirements and follows a slightly different approach for configuring. However I want to leave it here as an idea on how this could be resolved

@leokun
Copy link

leokun commented Feb 1, 2018

This feature would be really appreciated :)

@felipemarques
Copy link
Contributor

felipemarques commented Jun 13, 2018

Hey guys, any news about this ?
In my tests today, the only docker-compose.yaml that works, is this:

db:
    image: mysql:5.6
    #volumes:
    #    - .data/db:/var/lib/mysql
    restart: always
    environment:
        MYSQL_ROOT_PASSWORD: root
        MYSQL_DATABASE: mydb
        MYSQL_USER: root
        MYSQL_PASSWORD: root
web:
    image: nginx:latest
    ports:
        - "80:80"
        - "443:443"
    volumes:
        - ./project:/project
        - ./conf.d/site.conf:/etc/nginx/conf.d/site.conf
        - ./ssl:/etc/nginx/ssl
    environment:
        DOMAIN_NAME: my-php-project.test 
    links:
        - php
php:
    image: php:7-fpm
    volumes:
        - ./project:/project

If i try to use the version 2 or 3, does not work:

version: "2"
    services:
        db:
            image: mysql:5.6
            #volumes:
            #    - .data/db:/var/lib/mysql
            restart: always
            environment:
                MYSQL_ROOT_PASSWORD: root
                MYSQL_DATABASE: mydb
                MYSQL_USER: root
                MYSQL_PASSWORD: root
        web:
            image: nginx:latest
            ports:
                - "80:80"
                - "443:443"
            volumes:
                - ./project:/project
                - ./conf.d/site.conf:/etc/nginx/conf.d/site.conf
                - ./ssl:/etc/nginx/ssl
            environment:
                DOMAIN_NAME: my-php-project.test 
            links:
                - php
        php:
            image: php:7-fpm
            volumes:
                - ./project:/project

@iamluc
Copy link
Owner

iamluc commented Jun 13, 2018

Hi @felipemarques
Indeed, the DOMAIN_NAME environment variable is only used when your container use only the default "Bridge" network (== docker-compose file version 1)

We are discussing about this in #34

Also, please read https://github.com/iamluc/docker-hostmanager/pull/39/files

@nina-alin
Copy link

any news?

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

Successfully merging a pull request may close this issue.

7 participants