#container #docker #lxc #cli

bin+lib in-container

Determines if it is running in a container

3 releases (stable)

1.1.0 Jan 29, 2022
1.0.0 Jul 17, 2020

#2003 in Command line utilities

Download history 47/week @ 2024-03-11 8/week @ 2024-03-18 10/week @ 2024-03-25 76/week @ 2024-04-01 14/week @ 2024-04-08 23/week @ 2024-04-15 22/week @ 2024-04-22 10/week @ 2024-04-29 10/week @ 2024-05-06 8/week @ 2024-05-13 54/week @ 2024-05-20 9/week @ 2024-05-27 32/week @ 2024-06-03 5/week @ 2024-06-10 9/week @ 2024-06-17 7/week @ 2024-06-24

56 downloads per month
Used in putioarr

MIT/Apache

16KB
247 lines

in-container

in-container is a binary and a library that can be used to detect if you are running inside a container. Executing the binary will by default return exit-code 0 if it was run inside a container and exit-code 1 if it wasn't. The library can be included in an application of your choice, allowing you to determine whether your application is running inside a container or not.

(Please note that some of the detection mechanisms only work if in-container is executed in a privileged context.)

Supported operating systems/containerization solutions

If you are missing support for an operating system or container runtime, feel free to open a feature request or open a pull request.

Usage as a library

Add in-container as a dependency to your project's Cargo.toml:

[dependencies]
in-container = { version = "^1", default-features = false }

You can then use in_container::in_container() which will return true if you are running inside a container and false otherwise. In case you are interested in the container-runtime that was detected, you can call in_container::get_container_runtime() instead, which will return an Option<ContainerRuntime>. The Option is None when not running in a container, otherwise it will contain the detected runtime.

Version bump policy

In general, the versioning scheme follows the semantic versioning guidelines:

  • The patch version is bumped when backwards compatible fixes are made (this includes updates to dependencies).
  • The minor version is bumped when new features are introduced, but backwards compatibility is retained.
  • The major version is bumped when a backwards incompatible change was made.

Special case:

  • A bump in the minimum supported Rust version (MSRV) for the library, which is currently 1.52.1, will be done in minor version updates (i.e. they do not require a major version bump).
  • A bump in the minimum supported Rust version (MSRV) for the binary, which is currently 1.54.0, will be done in patch version updates (i.e. they do not require a major or minor version bump).

License

This project is licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–8MB
~52K SLoC