https://github.com/kartikk-26/docker-container-lifecycle
This repository contains a hands-on Docker 101 puzzle designed to teach beginners how Docker containers behave like both processes and isolated filesystems.
https://github.com/kartikk-26/docker-container-lifecycle
devops-tools docker docker-compose docker-container
Last synced: 13 days ago
JSON representation
This repository contains a hands-on Docker 101 puzzle designed to teach beginners how Docker containers behave like both processes and isolated filesystems.
- Host: GitHub
- URL: https://github.com/kartikk-26/docker-container-lifecycle
- Owner: Kartikk-26
- Created: 2025-09-12T09:02:42.000Z (25 days ago)
- Default Branch: main
- Last Pushed: 2025-09-12T09:04:48.000Z (25 days ago)
- Last Synced: 2025-09-12T11:23:55.054Z (25 days ago)
- Topics: devops-tools, docker, docker-compose, docker-container
- Homepage: https://labs.iximiuz.com/challenges/docker-101-container-stop-and-restart?s=08
- Size: 293 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
---
# π³ Docker Container Lifecycle Puzzle Guide
## π Go and Try This Puzzle
To experience this challenge hands-on, visit the official Docker 101 puzzle:
π [Docker 101: Stop and Restart a Containerized Application](https://labs.iximiuz.com/challenges/docker-101-container-stop-and-restart?s=08)
This interactive lab allows you to practice stopping and restarting containers while exploring their filesystem.
---
## π§© What Is This Puzzle About?
This puzzle helps you understand **data persistence in Docker containers**.
* **Containers = processes**: You can start, stop, and restart them like regular programs.
* **Containers = mini-filesystems**: Each has its own isolated root filesystem, created from the Docker image plus a writable layer.π **Key idea**: Stopping a container keeps data; removing a container deletes it (unless you use volumes).
---
## π οΈ What Youβll Learn
* How to stop and restart containers.
* How to inspect and modify a containerβs filesystem.
* The difference between stopping and removing containers.
* How data persists across stops and starts but is lost when containers are removed.---
## π Step-by-Step Solution
### Step A: Add Some Records
1. Open the web interface of the finance tracker.
2. Add records like `Income 1000` or `Expense 200`.
3. Verify inside the container:```bash
docker exec -it CONTAINER_NAME_OR_ID cat /var/lib/app/ledger.txt
```You should see your records.
### Step B: Stop the Container
Run:
```bash
docker stop CONTAINER_NAME_OR_ID
```* Sends a `SIGTERM` for graceful shutdown.
* Docker forces `SIGKILL` if it takes too long.
* The web app becomes unresponsive.### Step C: Restart the Container
Run:
```bash
docker start CONTAINER_NAME_OR_ID
```* Container resumes with the same writable layer.
* Reload the web interface β **records are still there** π### Step D: Remove the Container
First, stop it (if still running):
```bash
docker stop CONTAINER_NAME_OR_ID
```Then remove it:
```bash
docker rm CONTAINER_NAME_OR_ID
```* Container and writable layer are deleted.
* Data inside `/var/lib/app/ledger.txt` **is gone**.### Step E: Start a New Container from the Same Image
Run:
```bash
docker run -d --name my-finance -p 8080:8080 registry.iximiuz.com/my-finance
```* Launches a fresh container.
* Open the web interface β **no old records exist**.---
## β Final Outcome
* **Stop β Start**: Data is preserved β
* **Remove β Run new**: Data is lost βThis demonstrates the difference between:
* Container lifecycle (stop/start keeps data)
* Container removal (removes data)---
## π§ Beginner-Friendly Summary
* A container = running program + mini computer with its own filesystem.
* Stop a container β nothing is lost.
* Remove a container β everything inside is deleted.
* New container from same image = fresh start.**Goal**: Show that stopping keeps data β , removing destroys data β
**One-liner**: Stopping a container is like putting your laptop to sleep; removing it is like throwing it away and buying a new one.
---
## πΌοΈ Visuals
### Container Filesystem Diagram

*Illustration of Docker's layered filesystem, showing the read-only image layers and the writable container layer.*
### Expected Output Screenshot

*Example of the terminal output after inspecting the container's filesystem.*
---
Feel free to explore the challenge and experiment with the steps to deepen your understanding of Docker container lifecycles and data persistence.