0

I have launched a number of docker containers with node process running inside them. Is there a way to programatically obtain the container ID in which a node process is running during runtime?

Docker version: 17.12.0-ce-mac49

Update: Most most recent attempt hasn't worked:

        const cp = require('child_process');
        const output = cp.execSync('cat /proc/self/cgroup | grep devices');
        console.log(output.toString('utf8'));

But I get the following error:

   Error: Command failed: cat /proc/self/cgroup | grep devices
   cat: /proc/self/cgroup: No such file or directory

       at checkExecSyncError (child_process.js:625:11)
       at Object.execSync (child_process.js:662:13)

The same issue is observed when using

cat /etc/hostname
Larry
  • 226
  • 1
  • 2
  • 17
  • Possible duplicate of [Docker, how to get container information from within the container?](https://stackoverflow.com/questions/20995351/docker-how-to-get-container-information-from-within-the-container) – David Maze Jul 18 '19 at 08:34
  • It is the default container `hostname`, and also is included in `/proc/self/cgroup`. – David Maze Jul 18 '19 at 08:34
  • @DavidMaze I've updated the original question using `/proc/self/group`. But that doesn't seem to work either – Larry Jul 18 '19 at 09:24
  • How about `const os = require('os'); console.log(os.hostname());`? – vrdrv Jul 18 '19 at 12:33

0 Answers0