Skip to content

Commit

Permalink
Update target-chrome-docker's runningInDocker check for cgroupsv2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Joel 'Aaron' Cohen committed Oct 11, 2023
1 parent 02c143c commit ca4700e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 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,10 @@ 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'));

Check failure on line 9 in packages/target-chrome-docker/src/get-network-host.js

View workflow job for this annotation

GitHub Actions / Static analysis

Replace `fs.readFileSync('/proc/self/mountinfo',·'utf8')` with `⏎······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 ca4700e

Please sign in to comment.