edit-icon download-icon

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:

  1. version: '3.2'
  2. services:
  3. test:
  4. image: 'wordpress:4'
  5. deploy:
  6. mode: replicated
  7. replicas: 1
  8. update_config:
  9. failure_action: continue
  10. restart_policy:
  11. condition: none
  12. networks:
  13. - swarmmode #Your custom network name.
  14. - testswarm #Your custom network name.
  15. networks: #Declare your custom networks.
  16. swarmmode:
  17. external: true
  18. testswarm:
  19. 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).

Thank you! We've received your feedback.