Skip to content

Commit

Permalink
Add Stop Docker container function
Browse files Browse the repository at this point in the history
  • Loading branch information
R6n0 committed Nov 30, 2020
1 parent d948ab8 commit c4cb601
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/lib/system/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const { pull } = require('./system.pull');
const { exec } = require('./system.exec');
const { createContainer } = require('./system.createContainer');
const { restartContainer } = require('./system.restartContainer');
const { stopContainer } = require('./system.stopContainer');
const { getNetworkMode } = require('./system.getNetworkMode');

const { shutdown } = require('./system.shutdown');
Expand Down Expand Up @@ -45,6 +46,7 @@ System.prototype.pull = pull;
System.prototype.exec = exec;
System.prototype.createContainer = createContainer;
System.prototype.restartContainer = restartContainer;
System.prototype.stopContainer = stopContainer;
System.prototype.getNetworkMode = getNetworkMode;

System.prototype.shutdown = shutdown;
Expand Down
21 changes: 21 additions & 0 deletions server/lib/system/system.stopContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const { PlatformNotCompatible } = require('../../utils/coreErrors');

/**
* @description Stop a container.
* @param {string} containerId - Container id.
* @returns {Promise<Object>} The state of the command.
* @example
* const state = await stopContainer(containerId);
*/
async function stopContainer(containerId) {
if (!this.dockerode) {
throw new PlatformNotCompatible('SYSTEM_NOT_RUNNING_DOCKER');
}

const container = await this.dockerode.getContainer(containerId);
return container.stop();
}

module.exports = {
stopContainer,
};

0 comments on commit c4cb601

Please sign in to comment.