From f44a46b2bb55b994d5c4d47304a05d1a901f67f1 Mon Sep 17 00:00:00 2001 From: pawan Date: Mon, 25 Aug 2025 18:13:14 +0530 Subject: [PATCH] feat(--cpus): add support for --cpus flag This commit adds support for the --cpus flag, allowing users to reproduce container CPU limits. The `docker inspect` command outputs this value as `NanoCpus`, an integer. However, the `docker run` command expects a floating-point number for the `--cpus` flag. This implementation correctly parses the `NanoCpus` integer and converts it to a floating-point number. For example, a value of 1,000,000,000 NanoCpus will be correctly represented as 1.0 in the generated `docker run` command. --- runlike/inspector.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/runlike/inspector.py b/runlike/inspector.py index 035c727..9c29acb 100644 --- a/runlike/inspector.py +++ b/runlike/inspector.py @@ -267,6 +267,11 @@ def parse_entrypoint(self): if len(entrypoints) > 0 and entrypoints != image_entrypoints: self.options.append("--entrypoint %s" % entrypoints[0]) + def parse_nanocpus(self): + cpus = self.get_container_fact("HostConfig.NanoCpus") + if cpus: + self.options.append(f'--cpus="{cpus/1000000000}"') + def format_cli(self): image = self.get_container_fact("Config.Image") self.options = [] @@ -309,6 +314,7 @@ def format_cli(self): self.parse_shm_size() self.parse_memory() self.parse_memory_reservation() + self.parse_nanocpus() stdout_attached = self.get_container_fact("Config.AttachStdout") if not stdout_attached: