@@ -20,10 +20,6 @@ module.exports = async function (docker, projectName, recipe, output) {
2020 } ;
2121
2222 if ( service . networks !== undefined ) {
23- //if netowrks > 1 (It doesnt seem possible to start a container by connecting to multiple networks at once.)
24- // To connect multiple networks "docker network connect" is used to connect additional networks.
25- // have to attach the network after container creation
26- // https://github.com/moby/moby/issues/29265
2723 if ( Array . isArray ( service . networks ) ) {
2824 for ( let index = 0 ; index < service . networks . length ; index ++ ) {
2925 let networkName = projectName + '_' + service . networks [ index ]
@@ -43,7 +39,7 @@ module.exports = async function (docker, projectName, recipe, output) {
4339 } else {
4440 let networkNames = Object . keys ( service . networks ) ;
4541 for ( let index = 0 ; index < networkNames . length ; index ++ ) {
46- let network = service . networks [ networkNames [ index ] ] ;
42+ let network = service . networks [ networkNames [ index ] ] || { } ;
4743 let networkName = projectName + '_' + networkNames [ index ]
4844 let networkTemplate = {
4945 'NetworkingConfig' : {
@@ -66,11 +62,12 @@ module.exports = async function (docker, projectName, recipe, output) {
6662 networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] . IPAMConfig [ 'LinkLocalIPs' ] = network . link_local_ips
6763 }
6864 if ( network . priority !== undefined ) {
69- //priority ??? - priority indicates in which order Compose implementation SHOULD connect the service’s containers to its networks. If unspecified, the default value is 0.
65+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] . priority = network . priority
66+ } else {
67+ networkTemplate . NetworkingConfig . EndpointsConfig [ networkName ] . priority = 0
7068 }
7169 if ( index === 0 )
7270 opts . NetworkingConfig . EndpointsConfig = networkTemplate . NetworkingConfig . EndpointsConfig
73-
7471 networksToAttach . push ( networkTemplate . NetworkingConfig . EndpointsConfig )
7572 }
7673 }
@@ -96,16 +93,14 @@ module.exports = async function (docker, projectName, recipe, output) {
9693 opts . Name = serviceName ;
9794 }
9895 try {
99- // maybe its a good idea create a task queue to perform container creations and related stuff by order/priority.
100- //console.log(util.inspect(networksToAttach, { showHidden: false, depth: null }))
101- //console.log(util.inspect(opts, { showHidden: false, depth: null }))
10296 var container = await docker . createContainer ( opts ) ;
10397
10498 if ( networksToAttach . length > 1 ) {
10599 let networkNames = Object . keys ( networksToAttach [ 0 ] ) ;
106100 let network = findNetwork ( output , networkNames [ 0 ] )
107101 await network . disconnect ( { 'Container' : container . id } )
108- for ( var networkToAttach of networksToAttach ) {
102+ let networksToAttachSorted = tools . sortNetworksToAttach ( networksToAttach )
103+ for ( var networkToAttach of networksToAttachSorted ) {
109104 let networkName = Object . keys ( networkToAttach ) ;
110105 let network = findNetwork ( output , networkName )
111106 await network . connect ( { 'Container' : container . id , 'EndpointConfig' : networkToAttach [ networkName ] } )
0 commit comments