Skip to content

[Docker] Config.isDocker is not right in some Docker version / Linux distribution #84

@JasLin

Description

@JasLin

Updated by @zixia

There's so many difference between Docker container and the Linux distribution.

It seems that we have to list all the docker /proc/self/cgroup files by ourselves...

  1. Ubuntu 16.04
    1:name=systemd:/init.scope

  2. Docker version 1.9.1-circleci-cp-workaround, build 517b158(LXC Container in CircleCI)
    2:cpuset:/user/1001.user/13034.session/lxc/box2176/lxc/5cd9c2d7f4a7be56db6b79afdf65376bc882c0fa98dd187cda3bf61082041c09

  3. Debian 8@VPS of Google Cloud:
    1:name=systemd:/system.slice/ssh.service

  4. Docker version 1.12.1, build 23cf638
    1:name=systemd:/docker/3dcbb75a8e932d16a2443afadbe6f02ff242d2665cc43e3f2c7926ae8fdd0633

See Also:

THE FOLLOWING IS THE ORIGNAL ISSUE POST


Run npm run doctor or wechaty run doctor(for docker user), paste output here

one ubuntu 16.04 (not a docker):

> wechaty@0.5.16 doctor /home/user1/apps/wechaty
> ts-node bin/doctor


#### Wechaty Doctor

1. Wechaty version: #git[4c5f713 fix & enhance docker entrypoint help & command parse, with unit tests]
2. Linux x64 version 4.4.0-45-generic memory 378/3919 MB
3. Docker: true
4. Node version: v7.0.0

Expected behavior

3. Docker: true

this expected to be false

Actual behavior

function isWechatyDocker() {
  /**
   * Continuous Integration System
   */
  const isCi = require('is-ci')
  if (isCi) {
    return false
  }

  /**
   * Cloud9 IDE
   */
  const c9 = Object.keys(process.env)
                  .filter(k => /^C9_/.test(k))
                  .length
  if (c9 > 7 && process.env['C9_PORT']) {
    return false
  }

  const cgroup = '/proc/1/cgroup'
  try       { fs.statSync(cgroup).isFile() }
  catch (e) { return false }

  // http://stackoverflow.com/a/20624315/1123955
  const line = execSync(`sort -n ${cgroup} 2>/dev/null | head -1`)
                .toString()
                .replace(/\n$/, '')

  // instead of `/`, docker will end with a container id
  if (/\/$/.test(line)) {
    return false
  }

  return true
}

but on ubuntu 16.04 ,wen run cat /proc/1/cgroup, it's returns not the same as the others version linux.

~$ cat /proc/1/cgroup
11:cpuset:/
10:perf_event:/
9:memory:/init.scope
8:pids:/init.scope
7:hugetlb:/
6:cpu,cpuacct:/init.scope
5:net_cls,net_prio:/
4:blkio:/init.scope
3:devices:/init.scope
2:freezer:/
1:name=systemd:/init.scope
~$ sort -n /proc/1/cgroup 2>/dev/null | head -1
1:name=systemd:/init.scope

it's no end with '/' , and method return true finnally

Steps to reproduce the behavior (and fixes, if any)

Paste the full output logs here with WECHATY_LOG=silly set

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions