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

Restricting the number of CPUs does not work with Docker and no way of passing "--cpus" flag while the creation of an instance #283

Open
j-danek opened this issue Nov 5, 2024 · 0 comments

Comments

@j-danek
Copy link

j-danek commented Nov 5, 2024

Hi, I am trying to setup a small number of connected containers with Docker for testing. In order to assure the same behavior on any HW, I am trying to restrict the number of CPUs for each container. And I am failing at that, while using the Docker-plugin. I have tried five ways to achieve my goal. For details see the following table and comments in the example file below.

  1. passing raw argument to instance
  2. setting provider options via provider_options
  3. setting the argument via "cpus" in platform's details
  4. setting provider options
  5. passing raw arguments to provider

After the creation of the container, I would like to have
# docker inspect headnode | grep NanoCpus
"NanoCpus": 1000000000,
instead of
"NanoCpus": 0,

Is there any way how to, at least, pass raw arguments to the Docker? Or do I have to write my own Ansible script for managing Docker instances, as suggested in this example?

 - - - - OS - - - - 
PRETTY_NAME="Ubuntu 22.04.4 LTS"

- - - Molecule - - - 
molecule 24.6.0 using python 3.10 
    ansible:2.17.0
    default:24.6.0 from molecule
    docker:2.1.0 from molecule_docker requiring collections: community.docker>=3.0.2 ansible.posix>=1.4.0

molecule.yml

---
dependency:
  name: galaxy

driver:
  name: docker

platforms:
  - name: headnode
    image: docker.io/geerlingguy/docker-ubuntu2204-ansible
    command: ${MOLECULE_DOCKER_COMMAND:-""}
    pre_build_image: true
    privileged: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup:rw
    cgroupns_mode: host
    docker_networks:  # might be used only once
      - name: molecule
        ipam_config:
          - subnet: 172.206.0.0/16
    networks:
      - name: molecule
        ipv4_address: 172.206.0.10
    instance_raw_config_args:      # 1st
      - '--cpus=1.0'               # 1st
    provider_options:              # 2nd
      cpus: "1.0"                  # 2nd
    cpus: 1                        # 3rd
    providers:                     # 4th
      - name: docker               # 4th
        type: docker               # 4th
        options:                   # 4th
          cpus: 1                  # 4th
    provider_raw_config_args:      # 5th
      - '--cpus=1.0'               # 5th

provisioner:
  name: ansible

verifier:
  name: ansible

...
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

No branches or pull requests

1 participant