File tree 1 file changed +23
-0
lines changed
1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ func GetContainerRuntime(tgid, pid int) ContainerRuntime {
150
150
return runtime
151
151
}
152
152
153
+ // Check for container specific files
154
+ runtime = detectContainerFiles ()
155
+ if runtime != RuntimeNotFound {
156
+ return runtime
157
+ }
158
+
153
159
return RuntimeNotFound
154
160
}
155
161
@@ -167,6 +173,23 @@ func getContainerRuntime(input string) ContainerRuntime {
167
173
return RuntimeNotFound
168
174
}
169
175
176
+ // Related implementation: https://github.com/systemd/systemd/blob/6604fb0207ee10e8dc05d67f6fe45de0b193b5c4/src/basic/virt.c#L523-L549
177
+ func detectContainerFiles () ContainerRuntime {
178
+ files := map [ContainerRuntime ]string {}
179
+ // https://github.com/containers/podman/issues/3586#issuecomment-661918679
180
+ files [RuntimePodman ] = "/run/.containerenv"
181
+ // https://github.com/moby/moby/issues/18355
182
+ files [RuntimeDocker ] = "/.dockerenv"
183
+
184
+ for runtime , file := range files {
185
+ if fileExists (file ) {
186
+ return runtime
187
+ }
188
+ }
189
+
190
+ return RuntimeNotFound
191
+ }
192
+
170
193
// GetContainerID returns the container ID for a process if it's running in a container.
171
194
// If pid is less than one, it returns the container ID for "self".
172
195
func GetContainerID (tgid , pid int ) string {
You can’t perform that action at this time.
0 commit comments