Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker stack deploy doesn't use overlay network created

I created an overlay network using this command:

docker network create --driver overlay --internal --subnet 192.168.0.0/24 test

and then I tried deploying a stack with one service. the stack's yaml file looks like:

---
version: "3.0"
services:
  web1:
    image: "test"
    ports:
       - "12023:22"
    hostname: "ard014-web1"
    networks:
      - test
networks:
  test:
    driver: overlay

I deploy the stack using the command:

docker stack deploy -c test.yaml test

if I check the networks with docker network ls I find new overlay network gets created with name test_test and the container uses this network instead of the already created one. is this an expected behavior? I want the stack to use the network I created manually instead of creating new network because I want to control the ip CIDR range used by the overlay network. how can I achieve that?

like image 688
tkyass Avatar asked Jul 28 '26 21:07

tkyass


1 Answers

To use an existing network, define it as "external":

version: "3.0"
services:
  web1:
    image: "test"
    ports:
       - "12023:22"
    hostname: "ard014-web1"
    networks:
      - test
networks:
  test:
    external: 
      name: test

More details here: https://docs.docker.com/compose/compose-file/#external-1

like image 163
BMitch Avatar answered Jul 30 '26 19:07

BMitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!