mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-26 13:31:54 +00:00
Add port command
This commit is contained in:
parent
edac7ebb5f
commit
cb10f66295
4 changed files with 32 additions and 1 deletions
1
index.d.ts
vendored
1
index.d.ts
vendored
|
|
@ -18,6 +18,7 @@ declare module "docker-compose" {
|
||||||
buildOne(service:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
buildOne(service:String, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
push(options: IDockerComposePushOptions): Promise<IDockerComposeResult>;
|
push(options: IDockerComposePushOptions): Promise<IDockerComposeResult>;
|
||||||
|
port(service:String, containerPort:String|Number, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IDockerComposeOptions {
|
interface IDockerComposeOptions {
|
||||||
|
|
|
||||||
16
index.js
16
index.js
|
|
@ -359,6 +359,21 @@ const logs = function (service, options) {
|
||||||
return execCompose('logs', args, options);
|
return execCompose('logs', args, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} service
|
||||||
|
* @param {string|number} containerPort
|
||||||
|
* @param {object} options
|
||||||
|
* @param {string} options.cwd
|
||||||
|
* @param {boolean} [options.log]
|
||||||
|
* @param {?(string|string[])} [options.config]
|
||||||
|
* @param {?object} [options.env]
|
||||||
|
* @param {?(string[]|Array<string|string[]>)} [options.composeOptions]
|
||||||
|
*/
|
||||||
|
const port = function(service, containerPort, options) {
|
||||||
|
const args = [service, containerPort]
|
||||||
|
return execCompose('port', args, options)
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
upAll,
|
upAll,
|
||||||
upMany,
|
upMany,
|
||||||
|
|
@ -378,4 +393,5 @@ module.exports = {
|
||||||
buildOne,
|
buildOne,
|
||||||
ps,
|
ps,
|
||||||
push,
|
push,
|
||||||
|
port,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,3 +4,5 @@ services:
|
||||||
db:
|
db:
|
||||||
image: mongo:3.4
|
image: mongo:3.4
|
||||||
container_name: compose_test_mongodb_2
|
container_name: compose_test_mongodb_2
|
||||||
|
ports:
|
||||||
|
- "5432"
|
||||||
|
|
|
||||||
|
|
@ -321,3 +321,15 @@ test('logs does follow service logs', async assert => {
|
||||||
assert.true(await isContainerRunning('/compose_test_mongodb'));
|
assert.true(await isContainerRunning('/compose_test_mongodb'));
|
||||||
assert.end();
|
assert.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('returns the port for a started service', async assert => {
|
||||||
|
const config = {
|
||||||
|
cwd: path.join(__dirname),
|
||||||
|
config: './docker-compose-2.yml'
|
||||||
|
}
|
||||||
|
await compose.upAll(config);
|
||||||
|
const port = await compose.port('db', 5432, config);
|
||||||
|
|
||||||
|
assert.true(port.out.match(/.*:[0-9]{1,5}/));
|
||||||
|
assert.end();
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue