-
-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No machine id when using Docker Desktop #4
Comments
This should already be handled here in #3, but maybe it's broken? py-machineid/machineid/__init__.py Lines 82 to 86 in 7869558
Let me know if you're open to a PR fixing this bug. |
Yes it is broken. Unfortunately, the |
Are you open to a PR fixing this? cc @juanbretti |
The current prioritization prevents me from getting involved via PR. The option /proc/self/mountinfo , when testing native inside of container, was also not delivering usable results. |
What version of Docker Engine are you running? I can't reproduce your issue with Docker Desktop. |
Can you also please provide a Docker container’s |
Let me know if this is still an issue. |
Closing due to no response. Please let me know if the issue is still happening and I'll reopen. |
I have a similar problem here, the one-liner uses to reproduce the problem:
The content of
The content of
docker version:
|
@YiuRULE works fine for me: $ docker run python:3.10 /bin/bash -c "pip install py-machineid && python -c 'import machineid; print(machineid.id())'"
# Collecting py-machineid
# Downloading py_machineid-0.4.3-py3-none-any.whl (4.4 kB)
# Installing collected packages: py-machineid
# Successfully installed py-machineid-0.4.3
# WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package # manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#
# [notice] A new release of pip is available: 23.0.1 -> 23.2.1
# [notice] To update, run: pip install --upgrade pip
#
# 6d68e6a3b0b3ccde00cf7138a03115936b7bf6cbb707f6fbc0babad1fd403395 See the hash at the end. Your original reproduction command did not print anything, by the way.
Open to a PR if you can determine a fix. |
Here the detailed output if needed:
|
Would you be open to a PR? Starting point: py-machineid/machineid/__init__.py Lines 80 to 89 in e3f518f
Looks like your |
For reference, here's my
|
Maybe we can try That seems to work for your |
Better yet, maybe we should grep on |
I pushed f079039, which should resolve this issue. Can everyone please test the master branch? docker run python:3.12 /bin/bash -c "pip install git+https://github.com/keygen-sh/py-machineid && python -c 'import machineid; print(machineid.id())'"
# => a3253158467771c17587282c2227440903a49639ccada8bbc536bf6c0ff97126 Aside: if anybody has tips for improving tests (mocking file system?), I'm all ears. 🙂 |
Hello @ezekg . Here are my tests on my root@docker_machine:/# grep 'systemd' /proc/self/mountinfo | cut -d/ -f3
1xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx7
root@docker_machine:/# grep '/data/docker/containers' /proc/self/mountinfo | cut -d/ -f5
root@docker_machine:/# grep '/var/lib/docker/containers' /proc/self/mountinfo | cut -d/ -f6 As you can see, the second and third, are not pulling any result. |
@juanbretti what version of Docker? Can you please share your Regardless, I readded the |
Here is the content of my
And the version of my Docker:
|
@juanbretti I updated master to grep on |
Looks good to me! |
I've tested against all 3 variants of |
Hi team. docker run python:3.11.6 /bin/bash -c "pip install py-machineid && python -c 'import machineid; machineid.id()'"
Collecting py-machineid
Obtaining dependency information for py-machineid from https://files.pythonhosted.org/packages/66/b0/613422fb18d26991813c37dcf41f3da7f50d1233cccd1bab5ef280f0d322/py_machineid-0.4.4-py3-none-any.whl.metadata
Downloading py_machineid-0.4.4-py3-none-any.whl.metadata (1.8 kB)
Downloading py_machineid-0.4.4-py3-none-any.whl (4.5 kB)
Installing collected packages: py-machineid
Successfully installed py-machineid-0.4.4
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
[notice] A new release of pip is available: 23.2.1 -> 23.3.1
[notice] To update, run: pip install --upgrade pip
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.11/site-packages/machineid/__init__.py", line 103, in id
raise Exception('failed to obtain id on platform {}'.format(platform))
Exception: failed to obtain id on platform linux docker --version
Docker version 24.0.7, build afdd53b I saw all the previous tests were performed on docker 20 and 23. Maybe the issue is only happening with the newer docker versions? I'm happy to give you any additional information you need to solve this issue |
@LucaNicosia please share the contents of I'm using Docker v24.0.6 and it works fine. Curious what would be causing this. |
Thanks @ezekg for the quick answer. 17512 13668 0:755 / / rw,relatime master:3651 - overlay overlay rw,lowerdir=/var/lib/docker/overlay2/l/TZJS3GP4RQCWZJYZPSRYIS5WBQ:/var/lib/docker/overlay2/l/GPSDLROM4FKAG32N7QVZYXJMWL:/var/lib/docker/overlay2/l/6HOYFNKZ4BHMSZ7LWKM7QFVPLD:/var/lib/docker/overlay2/l/B2VVBMPESRJGBAB5LJRMTPBW55:/var/lib/docker/overlay2/l/ZF4L67RZEBTTZ45UQ7KEN7JFZQ:/var/lib/docker/overlay2/l/MCCDH5IPBDM36SLRFAAJF6CQGV:/var/lib/docker/overlay2/l/P7DLHXASRUNW37K7KTKQQW2NX7:/var/lib/docker/overlay2/l/XRM3F6RUERLKCK3S7NVCLWGE4L:/var/lib/docker/overlay2/l/MCY3UVNXFXJFVWAHCSXNTAB3OY,upperdir=/var/lib/docker/overlay2/fee039a2b1cbb77bfecf3ac5c6ebe276fe44a765ed3b01070d72821b3f015543/diff,workdir=/var/lib/docker/overlay2/fee039a2b1cbb77bfecf3ac5c6ebe276fe44a765ed3b01070d72821b3f015543/work,nouserxattr
17513 17512 0:759 / /proc rw,nosuid,nodev,noexec,relatime - proc proc rw
17514 17512 0:760 / /dev rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755,inode64
17515 17514 0:761 / /dev/pts rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666
17516 17512 0:762 / /sys ro,nosuid,nodev,noexec,relatime - sysfs sysfs ro
17517 17516 0:30 / /sys/fs/cgroup ro,nosuid,nodev,noexec,relatime - cgroup2 cgroup rw
17518 17514 0:758 / /dev/mqueue rw,nosuid,nodev,noexec,relatime - mqueue mqueue rw
17519 17514 0:763 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k,inode64
17520 17512 259:2 /lib/docker/containers/ccafdfa582c308c87328801eea67a1c380eb447abfaa7b9c04beea6b60be8dec/resolv.conf /etc/resolv.conf rw,relatime - ext4 /dev/nvme0n1p2 rw
17521 17512 259:2 /lib/docker/containers/ccafdfa582c308c87328801eea67a1c380eb447abfaa7b9c04beea6b60be8dec/hostname /etc/hostname rw,relatime - ext4 /dev/nvme0n1p2 rw
17522 17512 259:2 /lib/docker/containers/ccafdfa582c308c87328801eea67a1c380eb447abfaa7b9c04beea6b60be8dec/hosts /etc/hosts rw,relatime - ext4 /dev/nvme0n1p2 rw
13669 17514 0:761 /0 /dev/console rw,nosuid,noexec,relatime - devpts devpts rw,gid=5,mode=620,ptmxmode=666
13670 17513 0:759 /bus /proc/bus ro,nosuid,nodev,noexec,relatime - proc proc rw
13671 17513 0:759 /fs /proc/fs ro,nosuid,nodev,noexec,relatime - proc proc rw
13672 17513 0:759 /irq /proc/irq ro,nosuid,nodev,noexec,relatime - proc proc rw
13673 17513 0:759 /sys /proc/sys ro,nosuid,nodev,noexec,relatime - proc proc rw
13674 17513 0:759 /sysrq-trigger /proc/sysrq-trigger ro,nosuid,nodev,noexec,relatime - proc proc rw
13675 17513 0:764 / /proc/asound ro,relatime - tmpfs tmpfs ro,inode64
13676 17513 0:765 / /proc/acpi ro,relatime - tmpfs tmpfs ro,inode64
13677 17513 0:760 /null /proc/kcore rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755,inode64
13678 17513 0:760 /null /proc/keys rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755,inode64
13679 17513 0:760 /null /proc/timer_list rw,nosuid - tmpfs tmpfs rw,size=65536k,mode=755,inode64
13680 17513 0:766 / /proc/scsi ro,relatime - tmpfs tmpfs ro,inode64
13689 17516 0:767 / /sys/firmware ro,relatime - tmpfs tmpfs ro,inode64
13880 17516 0:768 / /sys/devices/virtual/powercap ro,relatime - tmpfs tmpfs ro,inode64 |
Mybe, we could use something like this. if not id:
mountinfo = __read__('/proc/self/mountinfo')
if mountinfo:
if 'docker' in mountinfo:
id = __exec__("grep '/var/lib/docker/containers/.*/hostname' /proc/self/mountinfo | cut -d/ -f6")
if not id:
id = __exec__("grep '/data/docker/containers/.*/hostname' /proc/self/mountinfo | cut -d/ -f5")
if not id:
id = __exec__("grep '/@docker/containers/.*/hostname' /proc/self/mountinfo | cut -d/ -f4")
if not id:
id = __exec__("grep -oP '(?<=/)([a-f0-9]+)(?=/hostname)' /proc/self/mountinfo") |
@juanbretti open to a PR? What is we rolled all this up into the following? grep -oP '(?<=docker/containers/)([a-f0-9]+)(?=/hostname)' /proc/self/mountinfo That'd reduce false matches if something with a |
Released v0.4.5 that offers a wider support for docker run python:3.11.6 /bin/bash -c "pip install py-machineid==0.4.5 && python -c 'import machineid; print(machineid.id())'" Thanks for the starting point, @juanbretti. |
It works! Thanks! |
Hi,
unfortunately, py-machineid fails to retrieve an id when you are using Docker Desktop. The system where I found this issue was a Apple Macbook 2022 with Docker Desktop.
It seems as
cat /proc/self/cgroup
only returns0::/
. A fix, more like a workaround, is to start the docker container bydocker run --cgroupdns=host
but this is not sustainable for my project. As the idea is that the users start the container only with docker run . Issue is discussed here as well.What is still usable in containers running via Docker Desktop is the
/proc/self/mountinfo
.The text was updated successfully, but these errors were encountered: