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:
-
Keep the Container Running: Docker containers typically run a single main process. If that process finishes, the container stops.
sleep infinityis 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., usingdocker exec). -
Minimal Resource Usage:
sleep infinitydoesn't consume significant CPU or memory, making it ideal for keeping a container alive without wasting resources. -
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), thealpinecontainer would start, run nothing, and immediately exit, making it impossible to perform the subsequent verification steps.