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

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

Open FDiskas opened this issue 7 years ago • 8 comments

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 avatar Aug 29 '16 13:08 FDiskas

I confirm it is an issue for docker-compose v2

aistis- avatar Aug 30 '16 08:08 aistis-

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.

iamluc avatar Aug 30 '16 12:08 iamluc

Yes please fiix this.

FDiskas avatar Sep 01 '16 07:09 FDiskas

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

bernhardberger avatar Aug 28 '17 13:08 bernhardberger

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

bernhardberger avatar Sep 25 '17 15:09 bernhardberger

This feature would be really appreciated :)

leokun avatar Feb 01 '18 08:02 leokun

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

felipemarques avatar Jun 13 '18 13:06 felipemarques

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 https://github.com/iamluc/docker-hostmanager/pull/34

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

iamluc avatar Jun 13 '18 13:06 iamluc