Using pre-existing networks appears broken in 1.16.1
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.
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
@egee-irl can you please post it in new link. previous link is not working
@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
I can offer a similar example~ Hope everyone can solve this problem, it wastes me a whole night.
You saved my night. Thank you!