networks

Last Updated: Feb 12, 2018

Template version

Compose V1/V2

Compose V3

Container Service does not support the use of the networks label in Compose V2. That is because the network in Compose V2 allows the service container to start in the custom network, and the containers in Container Service are all in the same cross-host interconnected container network. For information about the network management and service discovery for Container Service, see Cross-host interconnected container network.

You can add applications into a custom network by using the networks label. For more information, see networks.

Compose V3

You can add a service to the custom network by specifying the application network when creating an application. You can implement inter-service communications by adding a service to one or more custom networks.

Note:

You cannot change the network for an application after you add the application to a custom network.

You cannot remove an application from the network after you add the application to the custom network. The application will be removed from the network only when you delete the application.

Orchestration example:

version:'3.2'

services:

test:

image:'wordpress:4'

deploy:

mode: replicated

replicas:1

update_config:

failure_action:continue

restart_policy:

condition: none

networks:

- swarmmode #Your custom network name.

- testswarm #Your custom network name.

networks:#Declare your custom networks.

swarmmode:

external:true

testswarm:

external:true

You must declare the custom networks to be used by your application. Otherwise, an error will be reported during the application deployment. external: true indicates that the custom network has been created. Therefore, Container Service will not try to create the custom network when the application is created, but will search for the custom network and add the application to the custom network.

Note: The external parameter cannot be used together with other network configuration parameters (driver, driver_opts, ipam, and internal).