moby / moby/swarmkit

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

Open
#2,035 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
3.7k
Forks
676
Avg merge
4d 9h
Merged PRs (30d)
6

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported setup with docker-swarm.yml, the accompanying .env file, and docker stack deploy --compose-file docker-swarm.yml web. Inspect the deployed service and /etc/hosts; done when the extra_hosts entries use the substituted IP addresses rather than only listing hostnames.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.