bollard icon indicating copy to clipboard operation
bollard copied to clipboard

Generic strategy for health checking a container?

Open bpmooch opened this issue 10 months ago • 1 comments

    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

bpmooch avatar Mar 29 '24 23:03 bpmooch