This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Detect you are running in a docker container - buildx #47420
Labels
kind/feature
Functionality or other elements that the project doesn't currently have. Features are new and shiny
status/0-triage
Description
I’m the maintainer of the dcli package which is intended to replace bash using dart as an alternate scripting language.
https://pub.dev/packages/dcli
DCli has a feature that allow users to run privileged code by running sudo.
When running in a docker container we don’t need to use sudo (it doesn’t exist anyway).
As such, dcli needs a generic way to detect if it is running in a docker container.
Previously we have used the presence of ‘/.dockerenv’ to determine if we are in a docker container.
It however looks like that when running under buildx the .dockerenv file no longer exists.
As such I’m looking of a reliable way of detecting if dcli is running in a docker container.
Is there any official/correct way to determine if you are running in a docker container?
You can see from this thread there are a few suggested ways but these are all rather hacky.
https://forums.docker.com/t/detect-you-are-running-in-a-docker-container-buildx/139673
We need a reliable, stable and documented method to determine if we are running in a container.
For the likes of dcli, relying of an environment variable being injected (or any other user action) isn't sustainable as the user is unlikely to know the requirement and dcli needs to behave correctly 'out of the box'.
The text was updated successfully, but these errors were encountered: