Skip to content

Commit d80b76a

Browse files
authored
Detect containerd containers (localstack#8071)
Check for marker files left by our Dockerfile first, but otherwise check for the mount filesystem type as containerd does not leave any obvious marker file around (e.g. `/.dockerenv`). Note: macos has a beta option to use containerd for managing images, and this change detects this case as well.
1 parent d500507 commit d80b76a

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

localstack/config.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,15 @@ def in_docker():
258258
if OVERRIDE_IN_DOCKER:
259259
return True
260260

261+
# check some marker files that we create in our Dockerfiles
262+
for path in [
263+
"/usr/lib/localstack/.community-version",
264+
"/usr/lib/localstack/.pro-version",
265+
"/tmp/localstack/.marker",
266+
]:
267+
if os.path.isfile(path):
268+
return True
269+
261270
# details: https://github.com/localstack/localstack/pull/4352
262271
if os.path.exists("/.dockerenv"):
263272
return True
@@ -291,6 +300,13 @@ def in_docker():
291300
os_hostname = socket.gethostname()
292301
if os_hostname and os_hostname in content:
293302
return True
303+
304+
# containerd does not set any specific file or config, but does use
305+
# io.containerd.snapshotter.v1.overlayfs as the overlay filesystem
306+
with open("/proc/1/mountinfo", "rt") as infile:
307+
if "io.containerd" in infile.read():
308+
return True
309+
294310
return False
295311

296312

0 commit comments

Comments
 (0)