diff --git a/lib/services.js b/lib/services.js index 42d3cdf..fe8ba29 100644 --- a/lib/services.js +++ b/lib/services.js @@ -171,7 +171,7 @@ async function up(docker, projectName, recipe, output, options) { }; if (service.networks !== undefined) { - servicesTools.buildNetworks(projectName, serviceName, service.networks, networksToAttach, opts); + servicesTools.buildNetworks(projectName, serviceName, service.networks, networksToAttach, opts, recipe.networks); } else { opts.HostConfig.NetworkMode = projectName + '_default'; opts.NetworkingConfig.EndpointsConfig[projectName + '_default'] = { diff --git a/lib/servicesTools.js b/lib/servicesTools.js index 9c1808d..87024fa 100644 --- a/lib/servicesTools.js +++ b/lib/servicesTools.js @@ -183,7 +183,13 @@ module.exports = { if (service.ports !== undefined) { this.buildPorts(service.ports, output); } - + if (service.devices !== undefined) { + output.Devices = service.devices.map((device) => ({ + CgroupPermissions: "mrw", + PathInContainer: device, + PathOnHost: device, + })); + } if (service.cpu_count !== undefined) { output.CpuCount = service.cpu_count; } @@ -486,10 +492,19 @@ module.exports = { return output; }, - buildNetworks: function (projectName, serviceName, serviceNetworks, networksToAttach, opts) { + buildNetworks: function (projectName, serviceName, serviceNetworks, networksToAttach, opts, toplevelNetworks) { if (Array.isArray(serviceNetworks)) { for (let index = 0; index < serviceNetworks.length; index++) { let networkName = projectName + '_' + serviceNetworks[index]; + // check if network is external + if (toplevelNetworks !== undefined) { + if (Object.keys(toplevelNetworks).includes(serviceNetworks[index])) { + if (toplevelNetworks[serviceNetworks[index]].external === true) { + // it is external network + networkName = toplevelNetworks[serviceNetworks[index]].name + } + } + } let networkTemplate = { NetworkingConfig: { EndpointsConfig: {}, @@ -509,7 +524,16 @@ module.exports = { let networkNames = Object.keys(serviceNetworks); for (let index = 0; index < networkNames.length; index++) { let network = serviceNetworks[networkNames[index]] || {}; - let networkName = projectName + '_' + networkNames[index]; + let networkName = projectName + '_' + serviceNetworks[index]; + // check if network is external + if (toplevelNetworks !== undefined) { + if (Object.keys(toplevelNetworks).includes(networkNames[index])) { + if (toplevelNetworks[networkNames[index]].external === true) { + // it is external network + networkName = toplevelNetworks[networkNames[index]].name + } + } + } let networkTemplate = { NetworkingConfig: { EndpointsConfig: {},