amicontained
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i amicontained

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • crobin