Docker application exists after using sleep() call inside the app in non-interactive mode

I have simple Rust application which run a for loop and calls thread::sleep() API after every iteration of for loop.

Expected: in non-interactive mode, contianer must run this app and print sleeping 1,2, … and finally print After sleep.

Problem: In non-interactive mode, contianer exits only after 1st call to sleep() API and does not execute any statement after first sleep() call inside for loop.

Base Image : Alpine latest (the problem is also observed in Debian latest so its nothing with distro)


pub fn run_test(&mut self) -> Result<Vec<TestResult>, Error> {
    log::info!("Starting test...");

    for i in 1..=5 {
        println!("Sleeping... {i}");
        stdout().flush().unwrap();
        thread::sleep(Duration::from_secs(1));
    }

    log::info!("After sleep ---------------");

    log::info!("test completed.");
    stdout().flush().unwrap();

    Ok(ghost_list)
}

Thanks,

  • Bhaskar
1 Like

How do you build the image, how do you run the container?

And what about interactive mode? Since you specifically mentioned non-interactive, I assume you tried interactive, but the container exits only when the process stopped. So you should probably find out why it stops which could require Rust skills. If the process failes for some reason, that would also cause the rest of the code not running.