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
[BUG] Inside docker container, virtual detection is physical #62506
Comments
Hi there! Welcome to the Salt Community! Thank you for making your first contribution. We have a lengthy process for issues and PRs. Someone from the Core Team will follow up as soon as possible. In the meantime, here’s some information that may help as you continue your Salt journey.
There are lots of ways to get involved in our community. Every month, there are around a dozen opportunities to meet with other contributors and the Salt Core team and collaborate in real time. The best way to keep track is by subscribing to the Salt Community Events Calendar. |
This comment was marked as outdated.
This comment was marked as outdated.
@OrangeDog Salt always provides
then more specifically
This however depends on if os.path.isfile("/proc/1/cgroup"):
try:
with salt.utils.files.fopen("/proc/1/cgroup", "r") as fhr:
fhr_contents = fhr.read()
if ":/lxc/" in fhr_contents:
grains["virtual"] = "container"
grains["virtual_subtype"] = "LXC"
elif ":/kubepods/" in fhr_contents:
grains["virtual_subtype"] = "kubernetes"
elif ":/libpod_parent/" in fhr_contents:
grains["virtual_subtype"] = "libpod"
else:
if any(
x in fhr_contents
for x in (":/system.slice/docker", ":/docker/", ":/docker-ce/")
):
grains["virtual"] = "container"
grains["virtual_subtype"] = "Docker"
except OSError:
pass which it does in my container (CentOS, Ubuntu as a host)
So I don't think this is "not a bug", but I don't think the bug is actually something caused by Salt. When I run any Docker container, it always contains cgroups with docker prefix/path. When i run the specific
Although I don't run systemd there, so that might be the case. @wica128 are you able to provide Dockerfile that reproduces this exact behaviour? |
interesting, just running the debian:latest image gives me a different result; i'm using debian bullseye as my host:
|
Hmm, that's weird. This is on my laptop (Ubuntu 20.04)
with
What kind of host OS it is and what is the Docker version? |
here's the host system:
docker version:
was also able to repro on a macbook pro m1 with the following docker version:
|
@wica128 @kennybytes Did any of you find solution? I just stubled upon the same bug. I run salt inside docker (build) inside VirtualBox 7.0 on Windows 11 but salt thinks it is in VirtualBox and not inside Docker.
Symptoms are exactly the same. No docker entry is in cgroups. Only:
VirtulBox OS:
Docker version
|
No, not yet unfortunately |
Workaround to detect docker by interface names I used:
|
This is probably the cause and it also suggest possible fixes: |
I'm running Docker Desktop 4.28.0 (139021) on MacOS Sonoma v14.4.1. The container in question is running Rocky Linux 8 with systemd enabled and my Docker Desktop is running the default cgroups configuration, which I believe uses cgroups v2. We are seeing the behavior with the grain returning Both |
Hi,
Description
I'm using docker containers, to develop salt states for our environment. Where I use salt to manage virtual and physical servers.
And I use grains:virtual to decide, what to run.
But in the running docker container, grains:virtual returns physical.
salt-call --local grains.item virtual
A solution would be to add docker to https://github.com/saltstack/salt/blob/master/salt/grains/core.py#L841
Because
systemd-detect-virt
returns docker.Setup
Docker container oraclelinux:8 with systemd enabled.
Steps to Reproduce the behavior
Install salt in the container and run
salt-call --local grains.item virtual
Expected behavior
That grains:virtual returns docker when running
salt-call --local grains.item virtual
Versions Report
The text was updated successfully, but these errors were encountered: