简体   繁体   中英

How to disable network generation on docker stack deploy

I am deploying a compose file onto the UCP via:

docker stack deploy -c docker-compose.yml custom-stack-name

In the end I want to deploy multiple compose files (each compose file describes the setup for a separate microservice) onto one docker network eg appsnetwork

version: "3"
services:

  service1:
    image: docker/service1
    networks:
      - appsnetwork

  customservice2:
    image: myprivaterepo/imageforcustomservice2
    networks:
      - appsnetwork

networks:
  appsnetwork:

The docker stack deploy command automatically creates a new network with a generated name like this: custom-stack-name_appsnetwork

What are my options?

Try to create the network yourself first

docker network create --driver=overlay --scope=swarm appsnetwork

After that make the network external in your compose

version: "3"
services:
  service1:
    image: nginx
    networks:
      - appsnetwork

networks:
  appsnetwork:
    external: true

After that running two copies of the stack

docker stack deploy --compose-file docker-compose.yml stack1
docker stack deploy --compose-file docker-compose.yml stack2

Docker inspect for both shows IP in same network

$ docker inspect 369b610110a9
  ...
            "Networks": {
                "appsnetwork": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.1.5"
                    },
                    "Links": null,
                    "Aliases": [
                        "369b610110a9"
                    ],

$ docker inspect e8b8cc1a81ed

            "Networks": {
                "appsnetwork": {
                    "IPAMConfig": {
                        "IPv4Address": "10.0.1.3"
                    },
                    "Links": null,
                    "Aliases": [
                        "e8b8cc1a81ed"
                    ],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM