edit-icon download-icon

Add an application to a custom network

Last Updated: Feb 08, 2018

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.

Limits

  • 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.

Create an application by using an image

Note: For how to create an application, see Create an application.

When setting the application configurations, select the custom network name in the Networks section. In this example, add the application to the custom networks swarmmode and testswarm.

1

Create an application by using an orchestration template

Note: For how to create an application, see Create an application.

Add the information related to the networks in the orchestration template. In this example, add the application to the custom networks swarmmode and testswarm.

2

Orchestration template:

  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.