Skip to content

About

Containerized Flask web server with health-check endpoints, built and deployed with Docker, monitored via Docker CLI, with CI that builds and smoke-tests the image

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

8 Commits

Folders and files

Repository files navigation

CodeAlpha_DockerWebServer

CodeAlpha DevOps Internship — Task 4: Web Server using Docker

A minimal Flask web server, fully containerized with Docker, demonstrating image build, container lifecycle management, health checks, and monitoring.

Project structure

CodeAlpha_DockerWebServer/
├── app.py                # Flask app: /, /health, /info routes
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
├── .dockerignore
└── .github/workflows/docker.yml

Prerequisites

  • Docker Desktop (or Docker Engine) installed — docker --version to confirm

Build & run (plain Docker)

docker build -t codealpha-webserver .
docker run -d -p 5000:5000 --name webserver codealpha-webserver

Visit:

  • http://localhost:5000/ — homepage
  • http://localhost:5000/health — JSON health check
  • http://localhost:5000/info — container hostname/env info

Build & run (Docker Compose — one command)

docker compose up -d --build

Stop and remove:

docker compose down

Demonstrating container lifecycle & monitoring

These are the commands to run (and screenshot) for your submission/video:

docker ps                          # list running containers
docker logs webserver              # view application logs
docker stats webserver             # live CPU/memory usage
docker exec -it webserver sh       # shell inside the running container
docker inspect webserver           # full container metadata
docker stop webserver              # stop
docker start webserver             # start again
docker restart webserver           # restart
docker rm -f webserver             # remove
docker images                      # list built images
docker rmi codealpha-webserver     # remove the image

Health checks

The Dockerfile and docker-compose.yml both define a HEALTHCHECK that pings /health every 30 seconds. After running the container, check its status with:

docker inspect --format='{{json .State.Health}}' webserver

A healthy status confirms the app is up inside the container.

Troubleshooting notes (for your README/video)

  • If port 5000 is already in use, change the host port: -p 5001:5000
  • If the container exits immediately, check docker logs webserver for a Python traceback (most likely a missing dependency or syntax error)
  • docker exec -it webserver sh lets you poke around the filesystem live to debug

CI

.github/workflows/docker.yml builds the image on every push, runs it, and hits /health as a smoke test — proving the image builds and the container boots correctly outside your machine too.

What this demonstrates (DevOps concepts)

  • Docker image build (layered, cached, non-root user for security)
  • Container lifecycle management (create/start/stop/restart/remove)
  • Health checks and monitoring (HEALTHCHECK, docker stats, /health endpoint)
  • Troubleshooting via docker logs / docker exec
  • One-command deployment via Docker Compose

About

Containerized Flask web server with health-check endpoints, built and deployed with Docker, monitored via Docker CLI, with CI that builds and smoke-tests the image

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages