What is `sleep infinity` for?

QuestionsQuestions8 SkillsProDec, 13 2025
0914

That's a great question!

In the docker run command:

docker run --network none --name isolated-container -d alpine sleep infinity

sleep infinity is the command that the Docker container will execute once it starts.

Here's why it's used:

  1. Keep the Container Running: Docker containers typically run a single main process. If that process finishes, the container stops. sleep infinity is a simple command that essentially tells the container to "sleep forever" (or for a very, very long time). This is a common trick to keep a container running indefinitely, even if it's not performing any active tasks, so you can interact with it later (e.g., using docker exec).

  2. Minimal Resource Usage: sleep infinity doesn't consume significant CPU or memory, making it ideal for keeping a container alive without wasting resources.

  3. For Inspection or Testing: In this specific step of your lab, its purpose is to create a long-running "isolated-container" that you can then inspect and verify has no network interface or internet access. If we didn't use sleep infinity (or another long-running command), the alpine container would start, run nothing, and immediately exit, making it impossible to perform the subsequent verification steps.

0 Comments

no data
Be the first to share your comment!