In robust CI/CD workflows, validating your Docker image before pushing to a registry helps catch runtime issues early. This guide shows you how to extend a GitLab CI pipeline with aDocumentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
docker_test job that consumes the image built by docker_build, verifies the /live endpoint, and ensures your container is production-ready.
CI/CD Pipeline Overview
Define your basic stages and shared variables in.gitlab-ci.yml:
| Stage | Job Name | Purpose |
|---|---|---|
| test | unit_testing | Execute unit tests |
| test | code_coverage | Generate code coverage reports |
| containerization | docker_build | Build Docker image and save as artifact |
| containerization | docker_test | Load the image, run container, and test /live |
Building and Archiving Docker Images
Thedocker_build job builds your Node.js app into a Docker image, then saves it as a tarball artifact for downstream jobs.
Artifacts are retained for 3 days by default. Adjust
expire_in to suit your retention policy.Make sure sensitive environment variables (like
MONGO_PASSWORD) are stored in GitLab CI/CD variables, not hard-coded.Testing the Docker Image Before Push
Thedocker_test job retrieves the saved image artifact, runs the container, and probes the /live endpoint using an Alpine container with wget.
docker_test:
- docker load: Imports the tarball into Docker.
- docker run: Starts the container on port 3000 in detached mode.
- docker inspect: Extracts the container’s IP address.
- wget: From an Alpine image, requests
http://$IP:3000/liveand checks for"live"in the response.
Node.js Health Check Endpoints
Below is the simplifiedapp.js. The /live endpoint returns { status: "live" } for liveness probes.
Pipeline Visualization

docker_test will only run once docker_build successfully produces and archives the image. A successful liveness check means the container is ready to be pushed.