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

Generic strategy for health checking a container? #397

Open
bpmooch opened this issue Mar 29, 2024 · 1 comment
Open

Generic strategy for health checking a container? #397

bpmooch opened this issue Mar 29, 2024 · 1 comment
Labels
question Further information is requested

Comments

@bpmooch
Copy link
Contributor

bpmooch commented Mar 29, 2024

    let id = docker
        .create_container::<&str, &str>(None, mysql_config)
        .await
        .expect("failed to create mysql container")
        .id;
    docker
        .start_container::<String>(&id, None)
        .await
        .expect("failed to start mysql container");

    // FIXME: might have to wait a big longer for mysql than minio
    // FIXME: this is just not a solution for verifying a container works
    let wait_duration = 2_500;
    sleep(Duration::from_millis(wait_duration)).await;
    println!(
        "waited {wait_duration} milliseconds before returning from mysql container initialization"
    );

I am writing a test that spins up a mysql container at the start, runs some tests in sequence, then stops and removes the mysql container. I am having trouble reliably connecting to the container when I start it using bollard. If I were to add a HEALTHCHECK instruction to the dockerfile of the mysql image, could I use bollard to query that status? I guess I'm searching for a good pattern to deal with the problem generally

@fussybeaver fussybeaver added the question Further information is requested label Mar 30, 2024
@paul-hansen
Copy link
Contributor

You're probably looking for inspect_container

if let Ok(inspect_response) = docker.inspect_container("container_name", None).await {
    if let Ok(state) = inspect_response.state {
        println!("{:?}", state.health);
    }
}

(have not tried that code so expect typos, but should be close from looking at the docs)

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

No branches or pull requests

3 participants