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

resource_constraints param: --cpu #182

Open
alexsunxl opened this issue Dec 6, 2021 · 2 comments
Open

resource_constraints param: --cpu #182

alexsunxl opened this issue Dec 6, 2021 · 2 comments

Comments

@alexsunxl
Copy link

how can i use ‘--cpus’ directly

https://docs.docker.com/config/containers/resource_constraints/#cpu

@fussybeaver
Copy link
Owner

As it says in the docs, you'll need to use a combination of cpu_period and cpu_quota.

I haven't tested it, but maybe something like:

    let docker = Docker::connect_with_socket_defaults().unwrap();

    const IMAGE: &'static str = "alpine:3";

    docker
        .create_image(
            Some(CreateImageOptions {
                from_image: IMAGE,
                ..Default::default()
            }),
            None,
            None,
        )
        .try_collect::<Vec<_>>()
        .await?;

    let alpine_config = Config {
        image: Some(IMAGE),
        tty: Some(true),
        host_config: Some(HostConfig {
            cpu_period: Some(100000),
            cpu_quota: Some(150000),
            ..Default::default()
        }),
        ..Default::default()
    };

    let id = docker
        .create_container::<&str, &str>(None, alpine_config)
        .await?
        .id;
    docker.start_container::<String>(&id, None).await?;

@alexsunxl
Copy link
Author

@fussybeaver Hello
I know the combination of --cpu_period and --cpu_quota. But it's a little cumbersome, I just want to use --cpus only .

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

2 participants