diff --git a/package.json b/package.json index 69a42f94..58c8faf0 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "classnames": "^2.1.5", "coveralls": "^2.11.2", "deep-extend": "^0.4.0", - "dockerode": "^2.2.3", + "dockerode": "^2.2.7", "install": "^0.1.8", "jquery": "^2.1.3", "mixpanel": "kitematic/mixpanel-node", diff --git a/src/components/ContainerHomeFolders.react.js b/src/components/ContainerHomeFolders.react.js index c0a6366d..ad52f39d 100644 --- a/src/components/ContainerHomeFolders.react.js +++ b/src/components/ContainerHomeFolders.react.js @@ -28,17 +28,10 @@ var ContainerHomeFolder = React.createClass({ var mounts = _.clone(this.props.container.Mounts); var newSource = path.join(util.home(), util.documents(), 'Kitematic', this.props.container.Name, destination); - var binds = mounts.map(function (m) { - let source = m.Source; + mounts.forEach(m => { if (m.Destination === destination) { - source = newSource; + m.Source = util.windowsToLinuxPath(newSource); } - - if(util.isWindows()) { - return util.windowsToLinuxPath(source) + ':' + m.Destination; - } - - return source + ':' + m.Destination; }); mkdirp(newSource, function (err) { @@ -48,7 +41,7 @@ var ContainerHomeFolder = React.createClass({ } }); - containerActions.update(this.props.container.Name, {Binds: binds}); + containerActions.update(this.props.container.Name, {Mounts: mounts}); } }); } else { diff --git a/src/components/ContainerSettingsVolumes.react.js b/src/components/ContainerSettingsVolumes.react.js index f195badb..8c1e6158 100644 --- a/src/components/ContainerSettingsVolumes.react.js +++ b/src/components/ContainerSettingsVolumes.react.js @@ -27,14 +27,10 @@ var ContainerSettingsVolumes = React.createClass({ metrics.track('Choose Directory for Volume'); - if(util.isWindows()) { - directory = util.windowsToLinuxPath(directory); - } - var mounts = _.clone(this.props.container.Mounts); _.each(mounts, m => { if (m.Destination === dockerVol) { - m.Source = directory; + m.Source = util.windowsToLinuxPath(directory); } }); @@ -50,19 +46,14 @@ var ContainerSettingsVolumes = React.createClass({ from: 'settings' }); - var hostConfig = _.clone(this.props.container.HostConfig); - var binds = hostConfig.Binds; var mounts = _.clone(this.props.container.Mounts); _.each(mounts, m => { if (m.Destination === dockerVol) { m.Source = null; } }); - var index = _.findIndex(binds, bind => bind.indexOf(`:${dockerVol}`) !== -1); - if (index >= 0) { - binds.splice(index, 1); - } - containerActions.update(this.props.container.Name, {HostConfig: hostConfig, Binds: binds, Mounts: mounts}); + + containerActions.update(this.props.container.Name, {Mounts: mounts}); }, handleOpenVolumeClick: function (path) { metrics.track('Opened Volume Directory', { diff --git a/src/utils/DockerUtil.js b/src/utils/DockerUtil.js index 3baa3140..f4227470 100644 --- a/src/utils/DockerUtil.js +++ b/src/utils/DockerUtil.js @@ -248,6 +248,11 @@ export default { existingData.Tty = existingData.Config.Tty; existingData.OpenStdin = existingData.Config.OpenStdin; } + + data.Mounts = data.Mounts || existingData.Mounts; + data.Binds = data.Mounts.map(m => m.Source + ':' + m.Destination); + + // Preserve Ports let networking = _.extend(existingData.NetworkSettings, data.NetworkSettings); if (networking && networking.Ports) { let exposed = _.reduce(networking.Ports, (res, value, key) => { @@ -273,8 +278,8 @@ export default { containerServerActions.error({name, error}); return; } - var oldPath = path.join(util.home(), 'Kitematic', name); - var newPath = path.join(util.home(), 'Kitematic', newName); + var oldPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', name)); + var newPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', newName)); this.client.getContainer(newName).inspect((error, container) => { if (error) { @@ -285,13 +290,12 @@ export default { if (fs.existsSync(oldPath)) { fs.renameSync(oldPath, newPath); } - var binds = _.pairs(container.Volumes).map(function (pair) { - return pair[1] + ':' + pair[0]; + + container.Mounts.forEach(m => { + m.Source = m.Source.replace(oldPath, newPath); }); - var newBinds = binds.map(b => { - return b.replace(path.join(util.home(), 'Kitematic', name), path.join(util.home(), 'Kitematic', newName)); - }); - this.updateContainer(newName, {Binds: newBinds}); + + this.updateContainer(newName, {Mounts: container.Mounts}); rimraf(oldPath, () => {}); }); });