Introduction
In this lab, you will experience a scenario in the midst of a desert storm, where you encounter a menacing figure known as the "Desert Demon." Your goal is to navigate through the storm and learn the essential skill of stopping Docker containers in order to escape the demon's wrath.
Understanding Docker Container Execution
In this step, you will learn about the basics of Docker container execution and how to stop running containers.
First, let's run a simple Docker container using the
nginximage by executing the following command in your terminal:docker run -d --name my-nginx nginxNow, to stop the running container, use the following command:
docker stop my-nginxAfter executing the
docker stopcommand, the container will be stopped, and you can verify this by running the following command:docker ps -aYou should see that the stopped container is listed with a status of "Exited."
Graceful Shutdown of Containers
In this step, you will learn about the graceful shutdown of containers using the docker stop command.
Let's run a new container using the
alpineimage and execute a long-running command within the container:docker run -d --name long-running alpine sh -c "while :; do echo 'Long-running command...'; sleep 5; done"Now, initiate a graceful shutdown of the container by stopping it with the
docker stopcommand:docker stop long-runningVerify the status of the container by running:
docker ps -aThe container should be in a "Exited" state.
Summary
In this lab, the focus was on mastering the skill of stopping Docker containers. By following the scenarios presented and executing the provided steps, you gained practical experience in stopping running containers, ensuring a deeper understanding of container management within Docker. This will be invaluable in your journey to becoming proficient in Docker container management.



