moby / swarmkit

A toolkit for orchestrating distributed systems at any scale. It includes primitives for node discovery, raft-based consensus, task scheduling and more.
Apache License 2.0
3.35k stars 615 forks source link

The env file can't use in the swarm mode,the host can't replaced #2035

Open cjk87927 opened 7 years ago

cjk87927 commented 7 years ago

I have a docker-swarm.yml file like

version: "3"
services:
  cloud-storage:
    image:
      cloud-storage:base
    env_file: 
      .env  
    deploy:
      replicas: 2
    ports:
      - "8080:8080"  
    networks:
      - docker3
    extra_hosts:
      - "db.d17.cc:${IP_DB_MASTER}"
      - "storage.d17.cc:${IP_STORAGE}"
      - "img.d17.cc:${IP_IMG}"
      - "tracker.d17.cc:${IP_TRACKER}"
      - "memcache.d17.cc:${IP_MEMCACHE}"
networks:
  docker3:
    external:
      name: docker3

And I have .evn file in the same directory like :

IP_DB_MASTER=172.40.0.101
IP_STORAGE=172.40.0.102
IP_IMG=172.40.0.103
IP_TRACKER=172.40.0.104
IP_MEMCACHE=172.40.0.105

I deploy it use: docker stack deploy --compose-file docker-swarm.yml web and inspect:

[
    {
        "ID": "u8x4rfed42untn6xo0gi5uwjv",
        "Version": {
            "Index": 301
        },
        .....
                    "Env": [
                        "IP_DB_MASTER=117.41.176.166",
                        "IP_IMG=192.168.2.33",
                        "IP_MEMCACHE=117.41.176.165",
                        "IP_STORAGE=192.168.2.202",
                        "IP_STORAGE_1=172.40.0.102",
                        "IP_STORAGE_2=172.40.0.103",
                        "IP_STORAGE_NGINX=172.40.0.104",
                        "IP_TRACKER=172.40.0.101",
                        "VOLUMES_STORAGE_1=/data/docker/storage1",
                        "VOLUMES_STORAGE_2=/data/docker/storage2",
                        "VOLUMES_STORAGE_NGINX=/data/docker/nginx",
                        "VOLUMES_TRACKER=/data/docker/tracker"
                    ],
                    "Hosts": [
                        " db.d17.cc",
                        " img.d17.cc",
                        " memcache.d17.cc",
                        " storage.d17.cc",
                        " tracker.d17.cc"
                    ]
                },
               ......
    }
]

the Hosts not replaced

I enter the container and cat /etc/hosts

[root@9638a1bd3520 java]# cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.40.0.3      9638a1bd3520

Docker version 1.13.1

aluzzardi commented 7 years ago

@cjk87927 In the future, could you open these issues in the docker/docker repository? We keep all issues tracked on that repo.

I believe we do not support env variable substitution. Any reason why we're not doing that, @dnephin?

/cc @aaronlehmann

dnephin commented 7 years ago

Duplicate of https://github.com/docker/docker/issues/29133

env variable substitution is support. Reading a default .env file is not.