Might be a ContainerSupport issue on macOS Docker Engine

Plenty Su plenty.su at gmail.com
Wed Aug 24 09:52:52 UTC 2022


Hi,

I am trying the ContainerSupport feature.
https://bugs.openjdk.org/browse/JDK-8196595

This is my sample code
```
package com.example;

import com.sun.management.OperatingSystemMXBean;
import java.lang.management.ManagementFactory;
import java.util.concurrent.TimeUnit;

public class App {
  public static void main(String[] args) {
    OperatingSystemMXBean bean =
        (OperatingSystemMXBean)
ManagementFactory.getOperatingSystemMXBean();
    while (true) {
      System.out.println("processors: " + bean.getAvailableProcessors());
      System.out.println("memory: " + bean.getTotalPhysicalMemorySize());
      try {
        TimeUnit.SECONDS.sleep(5);
      } catch (Exception e) {
      }
    }
  }
}
```

I compiled this sample code with OpenJDK 8 without JVM argument
`-XX:+UseContainerSupport`,
and I dockerize it based on openjdk:8u342
```
FROM openjdk:8u342
COPY ./app/build/install/app /app
CMD [ "/app/bin/app" ]
```

Then, I ran this built image on Linux Docker Engine with the following
command
```
docker run --rm -it --cpus 1 -m 1G {image}
```

I got the output as I expected.
```
processors: 1
memory: 1073741824
```

However, when I tried to run the same built image on macOS Docker Engine
(Intel Chip) with the same image and command,
the output was my macOS Docker Engine's host information
```
processors: 4
memory: 6233055232
```
(My macOS Docker Engine has set resources limit to 4CPU and 6GB Memory)


I checked the cgroup files in the container. For example,
```
# cat /sys/fs/cgroup/memory.max
1073741824
```

It seems that macOS Docker Engine did set cgroup properly.

I also tried building the same application based on openjdk:17-alpine
(without re-compiling the code with JDK 17, only changing the base image)
```
FROM openjdk:17-alpine
COPY ./app/build/install/app /app
CMD [ "/app/bin/app" ]
```

and I tested the image with the same command on macOS.
It displayed the expected result.
```
> docker run --rm -it --cpus 1 -m 1G {image}
processors: 1
memory: 1073741824
```

I wonder if someone encounters the same case?

Thank you!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/jdk8u-dev/attachments/20220824/890440f7/attachment-0001.htm>


More information about the jdk8u-dev mailing list