Skip to content

Commit

Permalink
fix Docker detection on hosts with cgroup v2 (unified hierachy) (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
dfangl committed Jul 23, 2021
1 parent 034d3af commit 47cff41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions README.md
Expand Up @@ -268,7 +268,7 @@ Please be aware that the following configurations may have severe security impli

* `DISABLE_CORS_CHECKS`: Whether to disable all CSRF mitigations (default: 0).
* `DISABLE_CUSTOM_CORS_S3`: Whether to disable CORS override by S3 (default: 0).
* `DISABLE_CUSTOM_CORS_APIGATEWAY`: Whteher to disable CORS override by apigateway (default: 0).
* `DISABLE_CUSTOM_CORS_APIGATEWAY`: Whether to disable CORS override by apigateway (default: 0).
* `EXTRA_CORS_ALLOWED_ORIGINS`: Comma-separated list of origins that are allowed to communicate with localstack.
* `EXTRA_CORS_ALLOWED_HEADERS`: Comma-separated list of header names to be be added to `Access-Control-Allow-Headers` CORS header
* `EXTRA_CORS_EXPOSE_HEADERS`: Comma-separated list of header names to be be added to `Access-Control-Expose-Headers` CORS header
Expand All @@ -277,11 +277,12 @@ Please be aware that the following configurations may have severe security impli

* `SKIP_INFRA_DOWNLOADS`: Whether to skip downloading additional infrastructure components (e.g., specific Elasticsearch versions).
* `IGNORE_ES_DOWNLOAD_ERRORS`: Whether to ignore errors (e.g., network/SSL) when downloading Elasticsearch plugins.
* `OVERRIDE_IN_DOCKER`: Overrides the check whether LocalStack is executed within a docker container. If set to true, LocalStack assumes it runs in a docker container. Should not be set unless necessary.

### Debugging Configurations

The following environment configurations can be useful for debugging:
* `DEVELOP`: Starts a debugpy server before starting Localstack services
* `DEVELOP`: Starts a debugpy server before starting LocalStack services
* `DEVELOP_PORT`: Port number for debugpy server
* `WAIT_FOR_DEBUGGER`: Forces LocalStack to wait for a debugger to start the services

Expand Down
7 changes: 7 additions & 0 deletions localstack/config.py
Expand Up @@ -241,6 +241,9 @@ def is_env_not_false(env_var_name):
# whether to skip waiting for the infrastructure to shut down, or exit immediately
FORCE_SHUTDOWN = is_env_not_false("FORCE_SHUTDOWN")

# whether the in_docker check should always return true
OVERRIDE_IN_DOCKER = is_env_true("OVERRIDE_IN_DOCKER")


def has_docker():
try:
Expand Down Expand Up @@ -356,6 +359,10 @@ def in_docker():
Returns True if running in a docker container, else False
Ref. https://docs.docker.com/config/containers/runmetrics/#control-groups
"""
if OVERRIDE_IN_DOCKER:
return True
if os.path.exists("/.dockerenv"):
return True
if not os.path.exists("/proc/1/cgroup"):
return False
try:
Expand Down

0 comments on commit 47cff41

Please sign in to comment.