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.
CodeAlpha_DockerWebServer/
├── app.py # Flask app: /, /health, /info routes
├── requirements.txt
├── Dockerfile
├── docker-compose.yml
├── .dockerignore
└── .github/workflows/docker.yml
- Docker Desktop (or Docker Engine) installed —
docker --versionto confirm
docker build -t codealpha-webserver .
docker run -d -p 5000:5000 --name webserver codealpha-webserverVisit:
http://localhost:5000/— homepagehttp://localhost:5000/health— JSON health checkhttp://localhost:5000/info— container hostname/env info
docker compose up -d --buildStop and remove:
docker compose downThese 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 imageThe 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}}' webserverA healthy status confirms the app is up inside the container.
- If port 5000 is already in use, change the host port:
-p 5001:5000 - If the container exits immediately, check
docker logs webserverfor a Python traceback (most likely a missing dependency or syntax error) docker exec -it webserver shlets you poke around the filesystem live to debug
.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.
- 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,/healthendpoint) - Troubleshooting via
docker logs/docker exec - One-command deployment via Docker Compose