Skip to content

Commit

Permalink
Update target-chrome-docker's runningInDocker check for cgroupsv2 (#478)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Oct 31, 2023
1 parent dd1665c commit fafedca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/target-chrome-docker/src/get-network-host.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ const fs = require('fs-extra');
const getNetworkHost = async (execute, dockerId) => {
let host = '127.0.0.1';

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

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

0 comments on commit fafedca

Please sign in to comment.