Gets the docker container id / checks if the app is running in a docker container via CLI or API.
yarn add docker-id
Two methods are available:
getContainerId(async version - uses
fs.readFile; does not throw anything at all in fail cases, just returns
getContainerIdSync(sync version - uses
The result is cached; subsequent calls will not result in additional file reads.
You can wrap the result with
Boolean() to turn it into a
false value. Useful if you want to just check
that the app is in a container or not.
nullif the id cannot be found or the app is not running in docker
- container id if it is found
// promisified / async versiongetContainerId// ------// sync versionconst containerId =// If you want to check if it is in docker or notconst isDocker = BooleancontainerId
- Outputs the id if found with an exit code of 0
- If not found, outputs an error message with an exit code of -1