mirror of
https://github.com/danbulant/docker-compose
synced 2026-05-19 04:18:32 +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>;
|
||||
ps(options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
push(options: IDockerComposePushOptions): Promise<IDockerComposeResult>;
|
||||
port(service:String, containerPort:String|Number, options: IDockerComposeOptions): Promise<IDockerComposeResult>;
|
||||
}
|
||||
|
||||
interface IDockerComposeOptions {
|
||||
|
|
|
|||
16
index.js
16
index.js
|
|
@ -359,6 +359,21 @@ const logs = function (service, 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 = {
|
||||
upAll,
|
||||
upMany,
|
||||
|
|
@ -378,4 +393,5 @@ module.exports = {
|
|||
buildOne,
|
||||
ps,
|
||||
push,
|
||||
port,
|
||||
};
|
||||
|
|
|
|||
|
|
@ -3,4 +3,6 @@ version: '2'
|
|||
services:
|
||||
db:
|
||||
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.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