Skip to content
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

Updated how we check if Docker is running to work with the new cgroup v2 system. #1259

Merged
merged 3 commits into from
Mar 15, 2024

Conversation

DDRRDDDD
Copy link
Contributor

Purpose of changes

While running CI tasks with Jenkins within a Docker environment, we encountered an unexpected behavior where the WDM returned the hostname as 'localhost' instead of the expected value. Upon further investigation, we discovered that the 'isRunningInsideDocker' method's command returned nothing when executed within a Docker container. This was attributed to the use of cgroup v2 on specific Linux operating systems, as the command is expected to only work with v1. Therefore, we identified and modified the command to be compatible with cgroup v2, and i anticipate that it will pass the validation checks correctly.

Types of changes

  • Bug-fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

How has this been tested?

Setting up a testing environment on containers was very challenging. Instead, it will be replaced with the following resources.

Used a custom network, and the gateway is 172.20.0.1

Before the code change :
스크린샷 2024-03-15 오전 12 33 12

After the code change :
스크린샷 2024-03-15 오전 12 49 20

Confirmed that the results of the command are different inside and outside the container

Command Result (cgroup v2)

Inside Docker :
스크린샷 2024-03-15 오전 12 59 55

Outside Docker:
스크린샷 2024-03-15 오전 1 00 28

Reference:
https://stackoverflow.com/questions/68816329/how-to-get-docker-container-id-from-within-the-container-with-cgroup-v2
https://docs.docker.com/config/containers/runmetrics/

DDRRDDDD and others added 3 commits March 14, 2024 18:05
- Extracted the logic for checking Docker container presence into a private method named isCommandResultPresent().
- Modified the isRunningInsideDocker() method to utilize the isCommandResultPresent() method for checking both /proc/self/cgroup and /proc/self/mountinfo for Docker container presence.
@bonigarcia bonigarcia merged commit fce1910 into bonigarcia:master Mar 15, 2024
4 checks passed
@bonigarcia
Copy link
Owner

LGTM, thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants