compose icon indicating copy to clipboard operation
compose copied to clipboard

Using pre-existing networks appears broken in 1.16.1

Open egeexyz opened this issue 8 years ago • 4 comments

According to the Docker-Compose documentation listed here, using pre-existing networks is super simple:

networks: default: external: name: my-pre-existing-network

^ think of this in YAML formatting

But in my version (1.16.1 on Fedora 27), this syntax does not work. I get this error:services.my_container.networks.default contains unsupported option: 'external' Either the documentation is incorrect/misleading, or the version of Docker-Compose I am running is broken.

egeexyz avatar Dec 08 '17 04:12 egeexyz

Ok discovered the issue.

Some examples and documentation shown using networks in Docker Compose show the networks: nested within the services:. For default external networks to function, the networks: clause must be at the same level as the services: clause. Because indentation in markdown is kind of a pain, here's a working example in a Gist

egeexyz avatar Dec 08 '17 04:12 egeexyz

@egee-irl can you please post it in new link. previous link is not working

Ankit3794 avatar May 31 '19 13:05 Ankit3794

@egee-irl can you please post it in new link. previous link is not working

I can offer a similar example~ Hope everyone can solve this problem, it wastes me a whole night.

This is the one worked :

version: '3.5'

services:

  db:
    restart: unless-stopped
    image: mariadb
    container_name: charsdb
    volumes:
      - /usr/local/docker/mariadb/data:/var/lib/mysql
    environment: 
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=pass
    ports:
      - 3306:3306
    volumes:
      - /usr/local/docker/mariadb/data:/var/lib/mysql
      - /usr/local/docker/mariadb/config:/etc/mysql/conf.d
  charscloud:
    image: nextcloud
    container_name: charscloud
    depends_on:
      - db
    restart: unless-stopped
    volumes:
      - /usr/local/docker/nextcloud/data:/var/www/html
      - /usr/local/docker/nextcloud/config:/var/www/html/config
      - /usr/local/docker/nextcloud/custom_apps:/var/www/html/custom_apps
      - /usr/local/docker/nextcloud/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS=domain.me
    ports:
      - 13951:80
networks:
  default:
    external:
      name: charshell_network

This is the one failed :

version: '3.5'

services:

  db:
    restart: unless-stopped
    image: mariadb
    container_name: charsdb
    networks:
      default:
        external:
          name: charshell_network
    volumes:
      - /usr/local/docker/mariadb/data:/var/lib/mysql
    environment: 
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=pass
    ports:
      - 3306:3306
    volumes:
      - /usr/local/docker/mariadb/data:/var/lib/mysql
      - /usr/local/docker/mariadb/config:/etc/mysql/conf.d
  charscloud:
    image: nextcloud
    container_name: charscloud
    networks:
      default:
        external:
          name: charshell_network
    depends_on:
      - db
    restart: unless-stopped
    volumes:
      - /usr/local/docker/nextcloud/data:/var/www/html
      - /usr/local/docker/nextcloud/config:/var/www/html/config
      - /usr/local/docker/nextcloud/custom_apps:/var/www/html/custom_apps
      - /usr/local/docker/nextcloud/themes:/var/www/html/themes
      - /etc/localtime:/etc/localtime:ro
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS=domain.me
    ports:
      - 13951:80

Charshell avatar Mar 22 '20 16:03 Charshell

I can offer a similar example~ Hope everyone can solve this problem, it wastes me a whole night.

You saved my night. Thank you!

setchring avatar Jan 07 '21 19:01 setchring