Skip to content

Commit fafedca

Browse files
remleduffJoel 'Aaron' Cohenoblador
authored
Update target-chrome-docker's runningInDocker check for cgroupsv2 (#478)
* Update target-chrome-docker's runningInDocker check for cgroupsv2 This fixes docker-in-docker for me, particularly in gitlab. Without this, it tries to connect to 127.0.0.1 rather than the container's correct IP address and fails with a timeout. * Fix formatting --------- Co-authored-by: Joel 'Aaron' Cohen <acohen@deepsig.ai> Co-authored-by: Joel Arvidsson <joel@oblador.se>
1 parent dd1665c commit fafedca

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

packages/target-chrome-docker/src/get-network-host.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@ const fs = require('fs-extra');
33
const getNetworkHost = async (execute, dockerId) => {
44
let host = '127.0.0.1';
55

6-
// https://tuhrig.de/how-to-know-you-are-inside-a-docker-container/
6+
// https://stackoverflow.com/questions/68816329/how-to-get-docker-container-id-from-within-the-container-with-cgroup-v2
77
const runningInsideDocker =
8-
fs.existsSync('/proc/1/cgroup') &&
9-
/docker/.test(fs.readFileSync('/proc/1/cgroup', 'utf8'));
8+
fs.existsSync('/proc/self/mountinfo') &&
9+
/\/docker\/containers\//.test(
10+
fs.readFileSync('/proc/self/mountinfo', 'utf8')
11+
);
1012

1113
// If we are running inside a docker container, our spawned docker chrome instance will be a sibling on the default
1214
// bridge, which means we can talk directly to it via its IP address.

0 commit comments

Comments
 (0)