amicontained
Find out what container runtime is being used as well as features available. Ported from the Go version.
Last updated 3 years ago by crobin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install amicontained 
SYNC missed versions from official npm registry.

amicontained

This package helps detect if an application is currently running in a container.

Installation

npm install amicontained

Usage / API

const amicontained = require('amicontained');

amicontained.amIContained((err, result) => {
	if (err) {
		return console.error(err);
	}

	if (result) {
		console.log('I am running in a container!');
	} else {
		console.log('I am not running in a container!');
	}
});

amicontained.runtime((err, runtime) => {
	if (err) {
		return console.error(err);
	}

	console.log(`Current container runtime is ${runtime}`);
});

amicontained.hasPIDNamespace((err, result) => {
	if (err) {
		return console.error(err);
	}

	if (result) {
		console.log('PID is namespaced!');
	} else {
		console.log('PID is not namespaced!');
	}
});

amicontained.appArmorProfile((err, profile) => {
	if (err) {
		return console.error(err);
	}

	console.log(`Current apparmor profile is:\n\n${profile}`);
});

Running this file with docker would yield:

$ docker run --rm -it my-container:latest
I am contained!
Current container runtime is docker
PID is namespaced!

Promise-based

To use the API with promises, you can do:

const amicontained = require('amicontained').promisify();

amicontained.runtime().then((result) => {
	console.log(`Current container runtime is ${runtime}`);
});

Or if your version of node supports async/await:

const amicontained = require('amicontained').promisify();

async function main() {
	const runtime = await amicontained.runtime();
	console.log(runtime);
}

main();

License

MIT

Current Tags

  • 1.0.0                                ...           latest (3 years ago)

1 Versions

  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (2)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |