mirror of https://github.com/docker/docs.git
Merge pull request #1295 from docker/fix-volume-settings-bugs
Fix bug where renaming or editing container settings would cause volume settings to be lost
This commit is contained in:
commit
07c3c67bf5
|
|
@ -32,7 +32,7 @@
|
||||||
"classnames": "^2.1.5",
|
"classnames": "^2.1.5",
|
||||||
"coveralls": "^2.11.2",
|
"coveralls": "^2.11.2",
|
||||||
"deep-extend": "^0.4.0",
|
"deep-extend": "^0.4.0",
|
||||||
"dockerode": "^2.2.3",
|
"dockerode": "^2.2.7",
|
||||||
"install": "^0.1.8",
|
"install": "^0.1.8",
|
||||||
"jquery": "^2.1.3",
|
"jquery": "^2.1.3",
|
||||||
"mixpanel": "kitematic/mixpanel-node",
|
"mixpanel": "kitematic/mixpanel-node",
|
||||||
|
|
|
||||||
|
|
@ -28,17 +28,10 @@ var ContainerHomeFolder = React.createClass({
|
||||||
var mounts = _.clone(this.props.container.Mounts);
|
var mounts = _.clone(this.props.container.Mounts);
|
||||||
var newSource = path.join(util.home(), util.documents(), 'Kitematic', this.props.container.Name, destination);
|
var newSource = path.join(util.home(), util.documents(), 'Kitematic', this.props.container.Name, destination);
|
||||||
|
|
||||||
var binds = mounts.map(function (m) {
|
mounts.forEach(m => {
|
||||||
let source = m.Source;
|
|
||||||
if (m.Destination === destination) {
|
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) {
|
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 {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -27,14 +27,10 @@ var ContainerSettingsVolumes = React.createClass({
|
||||||
|
|
||||||
metrics.track('Choose Directory for Volume');
|
metrics.track('Choose Directory for Volume');
|
||||||
|
|
||||||
if(util.isWindows()) {
|
|
||||||
directory = util.windowsToLinuxPath(directory);
|
|
||||||
}
|
|
||||||
|
|
||||||
var mounts = _.clone(this.props.container.Mounts);
|
var mounts = _.clone(this.props.container.Mounts);
|
||||||
_.each(mounts, m => {
|
_.each(mounts, m => {
|
||||||
if (m.Destination === dockerVol) {
|
if (m.Destination === dockerVol) {
|
||||||
m.Source = directory;
|
m.Source = util.windowsToLinuxPath(directory);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -50,19 +46,14 @@ var ContainerSettingsVolumes = React.createClass({
|
||||||
from: 'settings'
|
from: 'settings'
|
||||||
});
|
});
|
||||||
|
|
||||||
var hostConfig = _.clone(this.props.container.HostConfig);
|
|
||||||
var binds = hostConfig.Binds;
|
|
||||||
var mounts = _.clone(this.props.container.Mounts);
|
var mounts = _.clone(this.props.container.Mounts);
|
||||||
_.each(mounts, m => {
|
_.each(mounts, m => {
|
||||||
if (m.Destination === dockerVol) {
|
if (m.Destination === dockerVol) {
|
||||||
m.Source = null;
|
m.Source = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var index = _.findIndex(binds, bind => bind.indexOf(`:${dockerVol}`) !== -1);
|
|
||||||
if (index >= 0) {
|
containerActions.update(this.props.container.Name, {Mounts: mounts});
|
||||||
binds.splice(index, 1);
|
|
||||||
}
|
|
||||||
containerActions.update(this.props.container.Name, {HostConfig: hostConfig, Binds: binds, Mounts: mounts});
|
|
||||||
},
|
},
|
||||||
handleOpenVolumeClick: function (path) {
|
handleOpenVolumeClick: function (path) {
|
||||||
metrics.track('Opened Volume Directory', {
|
metrics.track('Opened Volume Directory', {
|
||||||
|
|
|
||||||
|
|
@ -248,6 +248,11 @@ export default {
|
||||||
existingData.Tty = existingData.Config.Tty;
|
existingData.Tty = existingData.Config.Tty;
|
||||||
existingData.OpenStdin = existingData.Config.OpenStdin;
|
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);
|
let networking = _.extend(existingData.NetworkSettings, data.NetworkSettings);
|
||||||
if (networking && networking.Ports) {
|
if (networking && networking.Ports) {
|
||||||
let exposed = _.reduce(networking.Ports, (res, value, key) => {
|
let exposed = _.reduce(networking.Ports, (res, value, key) => {
|
||||||
|
|
@ -273,8 +278,8 @@ export default {
|
||||||
containerServerActions.error({name, error});
|
containerServerActions.error({name, error});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var oldPath = path.join(util.home(), 'Kitematic', name);
|
var oldPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', name));
|
||||||
var newPath = path.join(util.home(), 'Kitematic', newName);
|
var newPath = util.windowsToLinuxPath(path.join(util.home(), util.documents(), 'Kitematic', newName));
|
||||||
|
|
||||||
this.client.getContainer(newName).inspect((error, container) => {
|
this.client.getContainer(newName).inspect((error, container) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
@ -285,13 +290,12 @@ export default {
|
||||||
if (fs.existsSync(oldPath)) {
|
if (fs.existsSync(oldPath)) {
|
||||||
fs.renameSync(oldPath, newPath);
|
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, {Mounts: container.Mounts});
|
||||||
});
|
|
||||||
this.updateContainer(newName, {Binds: newBinds});
|
|
||||||
rimraf(oldPath, () => {});
|
rimraf(oldPath, () => {});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue