{"id":2302,"date":"2026-11-19T05:40:41","date_gmt":"2026-11-19T05:40:41","guid":{"rendered":"https:\/\/devopsschool.org\/blog\/?p=2302"},"modified":"2026-11-19T05:40:43","modified_gmt":"2026-11-19T05:40:43","slug":"ci-cd-hands-on-labs-with-docker-build-an-automated-pipeline","status":"publish","type":"post","link":"https:\/\/devopsschool.org\/blog\/ci-cd-hands-on-labs-with-docker-build-an-automated-pipeline\/","title":{"rendered":"CI\/CD Hands-On Labs With Docker: Build an Automated Pipeline"},"content":{"rendered":"\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"572\" src=\"https:\/\/devopsschool.org\/blog\/wp-content\/uploads\/2026\/11\/image-26.png\" alt=\"\" class=\"wp-image-2303\" srcset=\"https:\/\/devopsschool.org\/blog\/wp-content\/uploads\/2026\/11\/image-26.png 1024w, https:\/\/devopsschool.org\/blog\/wp-content\/uploads\/2026\/11\/image-26-300x168.png 300w, https:\/\/devopsschool.org\/blog\/wp-content\/uploads\/2026\/11\/image-26-768x429.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Reading about continuous integration and continuous delivery only takes you so far. Real confidence in DevOps comes from wiring together source control, automated tests, container builds, and deployment scripts until a single code change moves reliably from your laptop to a running server. These <strong>CI\/CD Hands-On Labs With Docker<\/strong> walk you through that exact progression using one cohesive project.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Start Here: What You Will Build in These Labs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Across the next ten labs, you will build and automate the delivery lifecycle for a lightweight Python REST API called <code>task-pulse<\/code>. You will start by packaging <code>task-pulse<\/code> inside a Docker container on your local machine, connect the project to Git, and gradually construct an automated <strong>Docker CI\/CD pipeline<\/strong> using GitHub Actions and Docker Hub.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">By the end of these <strong>CI\/CD practical exercises<\/strong>, every <code>git push<\/code> to your repository will automatically:<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Validate your code and run automated unit and integration tests.<\/li>\n\n\n\n<li>Build a versioned Docker image tagged with the exact Git commit hash.<\/li>\n\n\n\n<li>Publish the verified image to a remote container registry.<\/li>\n\n\n\n<li>Deploy the updated container into a target environment and verify its health endpoint.<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">Throughout this journey, you will gain practical experience with Dockerfiles, container lifecycle commands, Git branching workflows, YAML pipeline definitions, Docker Compose multi-container networking, automated security scanning, and systematic troubleshooting. For engineers looking to deepen their practical foundation alongside structured guided workshops, DevOpsSchool serves as a helpful educational resource for building hands-on DevOps and CI\/CD fluency.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab Preparation: Set Up Your Docker and CI\/CD Environment<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Before writing code or configuring automation, verify that your local workstation and cloud accounts are ready. Working through these <strong>Docker hands-on labs<\/strong> requires a consistent baseline environment so that commands behave predictably.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Prerequisites Checklist<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Terminal and Git Proficiency:<\/strong> Familiarity with navigating directories, editing files, and running standard <code>git<\/code> commands in a Linux, macOS, or Windows WSL2 shell.<\/li>\n\n\n\n<li><strong>Docker Engine or Docker Desktop:<\/strong> Needed to build images and run containers locally.<\/li>\n\n\n\n<li><strong>Docker Compose (v2+):<\/strong> Included with modern Docker Desktop installations and available as the <code>docker-compose-plugin<\/code> on Linux.<\/li>\n\n\n\n<li><strong>Source Code Repository:<\/strong> A free GitHub account to host your code and run GitHub Actions workflows.<\/li>\n\n\n\n<li><strong>Container Registry Account:<\/strong> A free Docker Hub account to store and distribute your built images.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Verify Your Local Tools<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Open your terminal and run the following commands to confirm that Git, Docker, and Docker Compose are properly installed and running:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git --version\ndocker --version\ndocker compose version\ndocker run --rm hello-world\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Expected Outcome:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>git --version<\/code> outputs a version number such as <code>git version 2.43.0<\/code>.<\/li>\n\n\n\n<li><code>docker --version<\/code> outputs <code>Docker version 27.x.x<\/code> or similar.<\/li>\n\n\n\n<li><code>docker compose version<\/code> outputs <code>Docker Compose version v2.x.x<\/code>.<\/li>\n\n\n\n<li><code>docker run --rm hello-world<\/code> pulls a tiny test image, prints <code>\"Hello from Docker!\"<\/code>, and exits cleanly. If you receive a permission error on Linux, ensure your user belongs to the <code>docker<\/code> group (<code>sudo usermod -aG docker $USER<\/code>) and restart your shell session.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 1: Containerize a Simple Application<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Applications often fail when moved between machines because of missing libraries, conflicting runtime versions, or inconsistent environment variables. Containerization packages your application code alongside its exact runtime dependencies into an immutable unit.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the Project Directory and Application Files<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a workspace folder named <code>task-pulse<\/code> and add a simple Python Flask application along with a unit test file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p task-pulse\/tests\ncd task-pulse\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>requirements.txt<\/code> to pin the exact package versions your application needs:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Plaintext<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>flask==3.0.3\npytest==8.3.3\nrequests==2.32.3\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>app.py<\/code> with a root endpoint and a <code>\/health<\/code> endpoint that our CI\/CD pipeline will later use for verification:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nfrom flask import Flask, jsonify\n\napp = Flask(__name__)\n\nAPP_VERSION = os.getenv(\"APP_VERSION\", \"1.0.0\")\nAPP_ENV = os.getenv(\"APP_ENV\", \"local\")\n\n\n@app.route(\"\/\")\ndef index():\n    return jsonify({\n        \"service\": \"task-pulse\",\n        \"status\": \"running\",\n        \"version\": APP_VERSION,\n        \"environment\": APP_ENV\n    })\n\n\n@app.route(\"\/health\")\ndef health():\n    return jsonify({\"status\": \"healthy\"}), 200\n\n\nif __name__ == \"__main__\":\n    app.run(host=\"0.0.0.0\", port=5000)\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>tests\/test_app.py<\/code> so we have an automated test suite ready for later labs:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Python<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>from app import app\n\n\ndef test_index_route():\n    client = app.test_client()\n    response = client.get(\"\/\")\n    assert response.status_code == 200\n    data = response.get_json()\n    assert data&#091;\"service\"] == \"task-pulse\"\n    assert data&#091;\"status\"] == \"running\"\n\n\ndef test_health_route():\n    client = app.test_client()\n    response = client.get(\"\/health\")\n    assert response.status_code == 200\n    assert response.get_json() == {\"status\": \"healthy\"}\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Write the Dockerfile<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a file named <code>Dockerfile<\/code> in the root of <code>task-pulse<\/code> (with no file extension):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dockerfile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Use an official, lightweight Python runtime as the base image\nFROM python:3.12-slim\n\n# Prevent Python from writing .pyc files and enable unbuffered stdout\/stderr logs\nENV PYTHONDONTWRITEBYTECODE=1 \\\n    PYTHONUNBUFFERED=1\n\n# Set the working directory inside the container\nWORKDIR \/app\n\n# Copy dependency list first to leverage Docker layer caching\nCOPY requirements.txt .\n\n# Install dependencies without caching wheel archives to keep the image small\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy the application source code into the container\nCOPY app.py .\nCOPY tests\/ .\/tests\/\n\n# Document that the container listens on port 5000\nEXPOSE 5000\n\n# Define the default command to start the application\nCMD &#091;\"python\", \"app.py\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Understanding Key Dockerfile Instructions<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>FROM python:3.12-slim<\/code>: Pulls a minimal Debian-based Python image, reducing download size and attack surface compared to the full image.<\/li>\n\n\n\n<li><code>WORKDIR \/app<\/code>: Creates <code>\/app<\/code> inside the container and sets it as the active directory for all subsequent instructions.<\/li>\n\n\n\n<li><code>COPY requirements.txt .<\/code> before <code>COPY app.py .<\/code>: Docker caches each layer. Because <code>requirements.txt<\/code> changes less frequently than application code, Docker reuses the cached <code>pip install<\/code> layer during future builds, speeding up your <strong>Docker image build pipeline<\/strong>.<\/li>\n\n\n\n<li><code>EXPOSE 5000<\/code>: Serves as documentation for developers and orchestration tools indicating which network port the containerized process uses.<\/li>\n\n\n\n<li><code>CMD [\"python\", \"app.py\"]<\/code>: Specifies the executable and arguments run when a container starts.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Your directory structure should now look like this:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Plaintext<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>task-pulse\/\n\u251c\u2500\u2500 Dockerfile\n\u251c\u2500\u2500 app.py\n\u251c\u2500\u2500 requirements.txt\n\u2514\u2500\u2500 tests\/\n    \u2514\u2500\u2500 test_app.py\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 2: Build and Run Docker Images Manually<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Before automating anything in a CI server, you must verify that your <code>Dockerfile<\/code> builds cleanly and runs as expected locally. Manual verification isolates syntax errors and port misconfigurations early.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Build and Inspect the Image<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the build command from inside the <code>task-pulse<\/code> directory:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker build -t task-pulse:1.0.0 .\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The <code>-t<\/code> flag tags the image with a name (<code>task-pulse<\/code>) and version (<code>1.0.0<\/code>), while <code>.<\/code> tells Docker to use the current directory as the build context. Verify that the image exists locally:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker images task-pulse\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Run and Verify the Container<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Start a container in detached mode (<code>-d<\/code>), map host port <code>8080<\/code> to container port <code>5000<\/code> (<code>-p 8080:5000<\/code>), and assign a readable name:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker run -d --name task-pulse-local -p 8080:5000 task-pulse:1.0.0\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Test the running service using <code>curl<\/code> and inspect its logs and runtime metadata:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl http:\/\/localhost:8080\/health\ndocker logs task-pulse-local\ndocker inspect --format='{{.State.Status}} - IP: {{.NetworkSettings.IPAddress}}' task-pulse-local\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Expected Output:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>curl<\/code> returns <code>{\"status\":\"healthy\"}<\/code>.<\/li>\n\n\n\n<li><code>docker logs<\/code> displays Flask startup output (<code>* Running on all addresses (0.0.0.0)<\/code>).<\/li>\n\n\n\n<li><code>docker inspect<\/code> prints <code>running<\/code> along with the container&#8217;s internal bridge IP address.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Clean Up Local Containers<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Stop and remove the test container so port <code>8080<\/code> is free for upcoming exercises:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker stop task-pulse-local\ndocker rm task-pulse-local\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Investigating Build and Runtime Errors<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">If <code>docker build<\/code> fails during <code>pip install<\/code>, verify internet connectivity and package spelling in <code>requirements.txt<\/code>. If a container starts and immediately exits (<code>Exited (1)<\/code> in <code>docker ps -a<\/code>), run <code>docker logs &lt;container_name&gt;<\/code> to read the Python traceback\u2014most runtime exits stem from syntax errors or binding to <code>127.0.0.1<\/code> instead of <code>0.0.0.0<\/code> inside the container.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 3: Connect the Project With Git<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Version control is the backbone of <strong>continuous integration with Docker<\/strong>. Every automated build must trace back to a specific commit, author, and branch so teams can audit changes and roll back faulty releases quickly.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Initialize Git and Add <code>.gitignore<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Inside <code>task-pulse<\/code>, initialize a Git repository and create a <code>.gitignore<\/code> file to prevent temporary artifacts from polluting your repository:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git init -b main\ncat &lt;&lt; 'EOF' &gt; .gitignore\n__pycache__\/\n*.py&#091;cod]\n.pytest_cache\/\n.env\n.venv\/\nEOF\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Stage, Commit, and Push to a Remote Repository<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a new empty repository named <code>task-pulse<\/code> on GitHub (without initializing a README or license, so there are no merge conflicts). Then link your local repository and push your initial commit:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add .\ngit commit -m \"feat: add initial task-pulse API and Dockerfile\"\ngit remote add origin https:\/\/github.com\/&lt;your-username&gt;\/task-pulse.git\ngit push -u origin main\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How Branches and Commits Drive Automation<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a standard CI\/CD workflow, developers create feature branches (such as <code>git checkout -b feat\/add-metrics<\/code>), push commits, and open pull requests against <code>main<\/code>. CI systems listen for these webhook events\u2014running validation checks on pull requests and triggering full image builds and deployments when changes merge into <code>main<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 4: Create Your First Docker-Based CI Pipeline<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Running tests manually relies on human discipline. A continuous integration pipeline enforces automated checks on every code push, catching regressions within minutes before broken code reaches shared environments.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create the GitHub Actions Workflow File<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">GitHub Actions looks for YAML workflow definitions inside <code>.github\/workflows\/<\/code>. Create the directory and workflow file:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mkdir -p .github\/workflows\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>.github\/workflows\/ci-cd.yml<\/code>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>name: Task Pulse CI\/CD Pipeline\n\non:\n  push:\n    branches:\n      - main\n  pull_request:\n    branches:\n      - main\n\njobs:\n  validate-and-test:\n    name: Validate and Run Unit Tests\n    runs-on: ubuntu-latest\n\n    steps:\n      - name: Checkout source code\n        uses: actions\/checkout@v4\n\n      - name: Verify Docker environment\n        run: |\n          docker --version\n          docker compose version\n\n      - name: Set up Python 3.12\n        uses: actions\/setup-python@v5\n        with:\n          python-version: \"3.12\"\n\n      - name: Install dependencies and run pytest\n        run: |\n          python -m pip install --upgrade pip\n          pip install -r requirements.txt\n          pytest -v\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Explaining the Workflow Configuration<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>on: push<\/code> and <code>on: pull_request<\/code>: Configures the pipeline to trigger whenever commits are pushed directly to <code>main<\/code> or proposed via a pull request.<\/li>\n\n\n\n<li><code>runs-on: ubuntu-latest<\/code>: Provisions a clean, ephemeral Linux virtual machine hosted by GitHub with Docker pre-installed.<\/li>\n\n\n\n<li><code>actions\/checkout@v4<\/code>: Clones your repository into the runner workspace so subsequent commands can access <code>app.py<\/code>, <code>Dockerfile<\/code>, and <code>tests\/<\/code>.<\/li>\n\n\n\n<li><code>pytest -v<\/code>: Executes your unit test suite in verbose mode; if any assertion fails, the step exits with a non-zero status code and halts the workflow.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Trigger and Verify the Pipeline<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Commit and push the workflow file:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>git add .github\/workflows\/ci-cd.yml\ngit commit -m \"ci: add initial test workflow\"\ngit push origin main\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Expected Result:<\/strong> Navigate to the <strong>Actions<\/strong> tab in your GitHub repository. You will see <strong>Task Pulse CI\/CD Pipeline<\/strong> running and turning green once <code>pytest<\/code> passes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 5: Automate Docker Image Building<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once tests pass, your pipeline should produce an immutable artifact. Automating image builds inside CI eliminates &#8220;works on my machine&#8221; discrepancies and ensures every image follows uniform naming and tagging conventions.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Image Naming and Tagging Strategy<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Avoid relying solely on the mutable <code>:latest<\/code> tag. In <strong>Docker container automation<\/strong>, tag images with the short Git commit SHA (<code>${{ github.sha }}<\/code>) so every container running in an environment maps unambiguously to a specific commit in Git history.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Extend <code>.github\/workflows\/ci-cd.yml<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Add a <code>build-image<\/code> job that depends on <code>validate-and-test<\/code> via the <code>needs<\/code> keyword. If tests fail, the image build never runs.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <code> build-image:\n    name: Build and Verify Docker Image\n    runs-on: ubuntu-latest\n    needs: validate-and-test\n\n    steps:\n      - name: Checkout source code\n        uses: actions\/checkout@v4\n\n      - name: Extract short commit SHA\n        id: vars\n        run: echo \"SHORT_SHA=${GITHUB_SHA::7}\" &gt;&gt; $GITHUB_OUTPUT\n\n      - name: Build Docker image\n        run: |\n          docker build \\\n            --build-arg BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ') \\\n            -t task-pulse:${{ steps.vars.outputs.SHORT_SHA }} \\\n            -t task-pulse:latest \\\n            .\n\n      - name: Verify built image metadata\n        run: |\n          docker images task-pulse\n          docker image inspect task-pulse:${{ steps.vars.outputs.SHORT_SHA }} --format='Created: {{.Created}} | Size: {{.Size}} bytes'\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Commit and push this update. In the GitHub Actions log for <strong>Build and Verify Docker Image<\/strong>, confirm that <code>docker images<\/code> lists both your 7-character commit tag and <code>latest<\/code>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 6: Add Automated Testing Before Image Publishing<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Passing unit tests against raw Python files does not guarantee your containerized application works. Packaging errors\u2014such as forgetting to copy a file in the <code>Dockerfile<\/code> or exposing the wrong port\u2014only appear when running the actual container.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Adding Containerized Integration and Health Checks<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Extend the <code>build-image<\/code> job in <code>.github\/workflows\/ci-cd.yml<\/code> to run unit tests inside the container, start the container in the background, and verify its <code>\/health<\/code> endpoint over HTTP before allowing the pipeline to proceed:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <code>     - name: Run unit tests inside container\n        run: |\n          docker run --rm task-pulse:${{ steps.vars.outputs.SHORT_SHA }} pytest -v\n\n      - name: Integration test on running container\n        run: |\n          docker run -d --name ci-smoke-test -p 5000:5000 \\\n            -e APP_VERSION=${{ steps.vars.outputs.SHORT_SHA }} \\\n            -e APP_ENV=ci \\\n            task-pulse:${{ steps.vars.outputs.SHORT_SHA }}\n\n          # Wait briefly for Flask to bind to port 5000\n          for i in {1..10}; do\n            if curl -sf http:\/\/localhost:5000\/health; then\n              echo \"Health check passed!\"\n              break\n            fi\n            sleep 1\n          done\n\n          # Assert exact JSON payload from root endpoint\n          RESPONSE=$(curl -sf http:\/\/localhost:5000\/)\n          echo \"Root response: $RESPONSE\"\n          echo \"$RESPONSE\" | grep -q '\"environment\":\"ci\"'\n\n          docker stop ci-smoke-test\n          docker rm ci-smoke-test\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Failure Conditions<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Because GitHub Actions runs shell steps with <code>set -e<\/code> by default, any failed <code>pytest<\/code> assertion, unreachable <code>\/health<\/code> check, or missing string in <code>grep<\/code> immediately aborts the job. No unverified image ever reaches your registry.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 7: Push Docker Images to a Container Registry<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Images built on an ephemeral CI runner vanish as soon as the job finishes. Pushing verified images to a central registry such as Docker Hub makes them accessible to staging servers, production clusters, and team members.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Configure Secure Credentials<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Never hardcode passwords or access tokens in your <code>Dockerfile<\/code> or YAML files.<\/p>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li>Log in to Docker Hub, open <strong>Account Settings &gt; Personal access tokens<\/strong>, and generate a token with <strong>Read &amp; Write<\/strong> permissions.<\/li>\n\n\n\n<li>In your GitHub repository, navigate to <strong>Settings &gt; Secrets and variables &gt; Actions<\/strong> and create two repository secrets:\n<ul class=\"wp-block-list\">\n<li><code>DOCKERHUB_USERNAME<\/code>: Your Docker Hub username.<\/li>\n\n\n\n<li><code>DOCKERHUB_TOKEN<\/code>: The personal access token you generated.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Update the Pipeline to Tag and Push<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Update the <code>build-image<\/code> job in <code>.github\/workflows\/ci-cd.yml<\/code> to log in using your secrets, tag the image with your Docker Hub namespace (<code>${{ secrets.DOCKERHUB_USERNAME }}\/task-pulse<\/code>), and push it only on <code>main<\/code> branch builds (not untrusted pull requests):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <code>     - name: Log in to Docker Hub\n        if: github.ref == 'refs\/heads\/main'\n        uses: docker\/login-action@v3\n        with:\n          username: ${{ secrets.DOCKERHUB_USERNAME }}\n          password: ${{ secrets.DOCKERHUB_TOKEN }}\n\n      - name: Tag and push image to Docker Hub\n        if: github.ref == 'refs\/heads\/main'\n        run: |\n          IMAGE_REPO=\"${{ secrets.DOCKERHUB_USERNAME }}\/task-pulse\"\n          docker tag task-pulse:${{ steps.vars.outputs.SHORT_SHA }} $IMAGE_REPO:${{ steps.vars.outputs.SHORT_SHA }}\n          docker tag task-pulse:${{ steps.vars.outputs.SHORT_SHA }} $IMAGE_REPO:latest\n          docker push $IMAGE_REPO:${{ steps.vars.outputs.SHORT_SHA }}\n          docker push $IMAGE_REPO:latest\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Verify by Pulling the Remote Image<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Once the pipeline completes, pull the published image onto your local machine to confirm it is publicly retrievable:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker pull &lt;your-dockerhub-username&gt;\/task-pulse:latest\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 8: Run Multi-Container Applications With Docker Compose<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Real-world <strong>Docker DevOps projects<\/strong> rarely consist of a single stateless container. Web APIs typically depend on databases, caches, or message brokers. Docker Compose lets you define multi-service architectures, private networks, persistent volumes, and health-based startup ordering in one declarative file.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: Create <code>compose.yaml<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In the root of <code>task-pulse<\/code>, create <code>compose.yaml<\/code> to run the <code>task-pulse<\/code> API alongside a Redis cache service:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>services:\n  redis:\n    image: redis:7.4-alpine\n    container_name: task-pulse-redis\n    restart: unless-stopped\n    volumes:\n      - redis_data:\/data\n    healthcheck:\n      test: &#091;\"CMD\", \"redis-cli\", \"ping\"]\n      interval: 5s\n      timeout: 3s\n      retries: 5\n\n  api:\n    build:\n      context: .\n      dockerfile: Dockerfile\n    image: task-pulse:local\n    container_name: task-pulse-api\n    ports:\n      - \"8080:5000\"\n    environment:\n      APP_VERSION: \"1.1.0\"\n      APP_ENV: \"compose-lab\"\n      REDIS_HOST: \"redis\"\n    depends_on:\n      redis:\n        condition: service_healthy\n    healthcheck:\n      test: &#091;\"CMD\", \"python\", \"-c\", \"import urllib.request; urllib.request.urlopen('http:\/\/localhost:5000\/health')\"]\n      interval: 10s\n      timeout: 3s\n      retries: 3\n\nvolumes:\n  redis_data:\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">How Docker Compose Coordinates Services<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Service Networking:<\/strong> Compose creates an isolated bridge network where <code>api<\/code> can reach <code>redis<\/code> simply by using the hostname <code>redis<\/code>.<\/li>\n\n\n\n<li><strong>Startup Order (<code>depends_on<\/code>):<\/strong> Using <code>condition: service_healthy<\/code> ensures the API container waits until Redis responds to <code>redis-cli ping<\/code> before booting.<\/li>\n\n\n\n<li><strong>Persistent Storage (<code>volumes<\/code>):<\/strong> <code>redis_data<\/code> preserves database files across container restarts.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Start, Inspect, and Stop the Stack<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Run the multi-container stack locally:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose up -d --build\ndocker compose ps\ncurl http:\/\/localhost:8080\/\ndocker compose logs -f api\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">When finished inspecting, tear down the containers while preserving or removing volumes (<code>-v<\/code> removes volumes):<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Bash<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docker compose down -v\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 9: Automate Deployment Using a Docker Image<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Continuous deployment with Docker<\/strong> bridges the gap between a published registry artifact and a live environment. Instead of manually SSHing into servers to pull images, an automated deployment job replaces old containers safely and verifies service health immediately.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Lab Demonstration vs. Production Deployment<\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>Dimension<\/strong><\/td><td><strong>Lab Demonstration Deployment<\/strong><\/td><td><strong>Production Deployment<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>Target Host<\/strong><\/td><td>Single VM or simulated runner environment<\/td><td>Orchestrated cluster (Kubernetes, ECS) or multi-node Swarm<\/td><\/tr><tr><td><strong>Cutover Strategy<\/strong><\/td><td>Stop old container, start new container (brief downtime)<\/td><td>Rolling update or Blue\/Green deployment (zero downtime)<\/td><\/tr><tr><td><strong>Rollback Mechanism<\/strong><\/td><td>Re-run pipeline or <code>docker run<\/code> with previous SHA tag<\/td><td>Automated health-probe rollback and traffic shifting<\/td><\/tr><tr><td><strong>Secrets Injection<\/strong><\/td><td>Encrypted CI secrets passed via <code>-e<\/code> or <code>.env<\/code> file<\/td><td>Dedicated secrets manager (Vault, AWS Secrets Manager)<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Add a Deployment Job to <code>.github\/workflows\/ci-cd.yml<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In a real server setup, a deployment job connects over SSH (using a tool like <code>appleboy\/ssh-action<\/code>) or triggers a webhook on your target host. Below is a safe, self-contained deployment simulation job you can append to <code>.github\/workflows\/ci-cd.yml<\/code> to practice the exact pull-replace-verify sequence:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <code> deploy-staging:\n    name: Deploy to Staging Environment\n    runs-on: ubuntu-latest\n    needs: build-image\n    if: github.ref == 'refs\/heads\/main'\n\n    steps:\n      - name: Pull versioned image and roll out container\n        run: |\n          IMAGE_TAG=\"${{ secrets.DOCKERHUB_USERNAME }}\/task-pulse:${GITHUB_SHA::7}\"\n          echo \"Pulling verified artifact: $IMAGE_TAG\"\n          docker pull \"$IMAGE_TAG\"\n\n          # Gracefully stop and remove existing container if present\n          docker stop task-pulse-staging 2&gt;\/dev\/null || true\n          docker rm task-pulse-staging 2&gt;\/dev\/null || true\n\n          # Start updated container with production-like restart policy\n          docker run -d \\\n            --name task-pulse-staging \\\n            --restart unless-stopped \\\n            -p 8080:5000 \\\n            -e APP_VERSION=\"${GITHUB_SHA::7}\" \\\n            -e APP_ENV=\"staging\" \\\n            \"$IMAGE_TAG\"\n\n      - name: Post-deployment health verification\n        run: |\n          sleep 3\n          STATUS=$(curl -s -o \/dev\/null -w \"%{http_code}\" http:\/\/localhost:8080\/health)\n          if [ \"$STATUS\" -ne 200 ]; then\n            echo \"Deployment verification failed with HTTP $STATUS\"\n            docker logs task-pulse-staging\n            exit 1\n          fi\n          echo \"Staging deployment healthy (HTTP 200).\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">If the health check fails (<code>$STATUS -ne 200<\/code>), the job prints container logs and fails visibly, alerting your team immediately.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Lab 10: Improve the Pipeline With Security and Reliability Checks<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">Objective and Why It Matters<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Speed without guardrails creates operational risk. Hardening your <code>Dockerfile<\/code> and adding automated vulnerability scanning prevents compromised dependencies and overly permissive containers from reaching production.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Hardening the <code>Dockerfile<\/code><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Update <code>Dockerfile<\/code> to run as an unprivileged non-root user and exclude unnecessary build context files via a <code>.dockerignore<\/code> file.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create <code>.dockerignore<\/code>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Plaintext<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.git\n.github\n__pycache__\n.pytest_cache\n.env\ncompose.yaml\nREADME.md\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Update <code>Dockerfile<\/code> to create a dedicated <code>appuser<\/code>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Dockerfile<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>FROM python:3.12-slim\n\nENV PYTHONDONTWRITEBYTECODE=1 \\\n    PYTHONUNBUFFERED=1\n\nWORKDIR \/app\n\n# Create a non-root system user and group\nRUN groupadd --system appgroup &amp;&amp; useradd --system --gid appgroup appuser\n\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\nCOPY app.py .\nCOPY tests\/ .\/tests\/\n\n# Transfer ownership of application files to the non-root user\nRUN chown -R appuser:appgroup \/app\n\nUSER appuser\n\nEXPOSE 5000\nCMD &#091;\"python\", \"app.py\"]\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Add Vulnerability Scanning to Your Pipeline<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Integrate Trivy (an open-source container vulnerability scanner) into your <code>build-image<\/code> job right after <code>docker build<\/code> and before <code>docker push<\/code>. This ensures images with critical OS or Python package vulnerabilities are blocked before publication:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">YAML<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"> <code>     - name: Scan Docker image for HIGH and CRITICAL vulnerabilities\n        uses: aquasecurity\/trivy-action@0.28.0\n        with:\n          image-ref: \"task-pulse:${{ steps.vars.outputs.SHORT_SHA }}\"\n          format: \"table\"\n          exit-code: \"1\"\n          ignore-unfixed: true\n          severity: \"CRITICAL,HIGH\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Reliability Practices for Production Pipelines<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Pin Base Image Digests:<\/strong> For strict reproducibility, pin base images using SHA256 digests (<code>FROM python:3.12-slim@sha256:...<\/code>) alongside version tags.<\/li>\n\n\n\n<li><strong>Traceability Labels:<\/strong> Add OCI labels (<code>org.opencontainers.image.revision<\/code>) during <code>docker build<\/code> so operations teams can inspect any running container and identify its exact source commit.<\/li>\n\n\n\n<li><strong>Least-Privilege Access Control:<\/strong> Scope registry tokens to specific repositories and restrict deployment credentials to protected branches (<code>main<\/code>) with required pull request approvals.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Troubleshooting Workshop: Fix Common Docker CI\/CD Failures<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Even well-structured pipelines break. Use this diagnostic reference when troubleshooting failures across local machines or CI runners.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><td><strong>Failure Scenario<\/strong><\/td><td><strong>Likely Cause<\/strong><\/td><td><strong>Diagnostic Commands<\/strong><\/td><td><strong>Practical Resolution<\/strong><\/td><\/tr><\/thead><tbody><tr><td><strong>Docker daemon unavailable<\/strong><\/td><td>Docker Desktop is stopped, or the Linux <code>docker.service<\/code> is inactive.<\/td><td><code>systemctl status docker<\/code><br><code>docker info<\/code><\/td><td>Start Docker Desktop or run <code>sudo systemctl start docker<\/code>.<\/td><\/tr><tr><td><strong>Image build failures<\/strong><\/td><td>Missing dependency in <code>requirements.txt<\/code>, network timeout, or invalid syntax.<\/td><td><code>docker build --no-cache --progress=plain .<\/code><\/td><td>Inspect the exact failing <code>RUN<\/code> layer in plain logs and pin valid package versions.<\/td><\/tr><tr><td><strong>Incorrect Dockerfile paths<\/strong><\/td><td>Running <code>docker build<\/code> from the wrong directory or referencing files outside the build context.<\/td><td><code>pwd &amp;&amp; ls -la<\/code><\/td><td>Run <code>docker build -f path\/to\/Dockerfile .<\/code> from the project root directory.<\/td><\/tr><tr><td><strong>Permission problems<\/strong><\/td><td>Linux user lacks access to <code>\/var\/run\/docker.sock<\/code>, or non-root container user cannot write to a mounted volume.<\/td><td><code>id<\/code><br><code>ls -l \/var\/run\/docker.sock<\/code><\/td><td>Add user to <code>docker<\/code> group locally, or <code>chown<\/code> directories for <code>appuser<\/code> inside the Dockerfile.<\/td><\/tr><tr><td><strong>Failed application tests<\/strong><\/td><td>Code regression or missing environment variables during CI test execution.<\/td><td><code>pytest -vv --tb=short<\/code><\/td><td>Reproduce locally using the exact environment variables defined in your CI YAML.<\/td><\/tr><tr><td><strong>Registry authentication errors<\/strong><\/td><td>Expired Docker Hub token, typo in GitHub Secret name, or missing write permissions.<\/td><td><code>echo \"$DOCKERHUB_TOKEN\" | docker login -u \"$DOCKERHUB_USERNAME\" --password-stdin<\/code><\/td><td>Regenerate a Read\/Write personal access token and update repository secrets.<\/td><\/tr><tr><td><strong>Image tagging mistakes<\/strong><\/td><td>Mismatch between the tag built in Step A and the tag pushed or pulled in Step B.<\/td><td><code>docker images<\/code><\/td><td>Store the computed tag in a single CI output variable (<code>SHORT_SHA<\/code>) and reuse it everywhere.<\/td><\/tr><tr><td><strong>Port conflicts<\/strong><\/td><td>Another process or leftover container is already bound to host port <code>8080<\/code> or <code>5000<\/code>.<\/td><td><code>docker ps<\/code><br><code>ss -tulpn | grep 8080<\/code><\/td><td>Stop conflicting containers (<code>docker rm -f &lt;name&gt;<\/code>) or map a different host port (<code>-p 8081:5000<\/code>).<\/td><\/tr><tr><td><strong>Container startup failures<\/strong><\/td><td>Application crashes immediately due to missing required env vars or bad <code>CMD<\/code> syntax.<\/td><td><code>docker ps -a<\/code><br><code>docker logs &lt;container&gt;<\/code><\/td><td>Check exit code (<code>Exited (1)<\/code>) and verify <code>CMD<\/code> uses exec-form JSON array syntax.<\/td><\/tr><tr><td><strong>Deployment health-check failures<\/strong><\/td><td>Health probe runs before the application finishes booting, or app binds to <code>127.0.0.1<\/code>.<\/td><td><code>docker exec &lt;container&gt; curl -v http:\/\/localhost:5000\/health<\/code><\/td><td>Bind server to <code>0.0.0.0<\/code> and add a retry loop or Compose <code>healthcheck<\/code> with <code>start_period<\/code>.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Final Practical Challenge: Build an End-to-End Docker CI\/CD Project<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now that you have practiced each pipeline stage individually, combine them into an independent capstone exercise.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Project Brief<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Extend <code>task-pulse<\/code> (or build a new microservice such as a URL shortener or status tracker) with a new <code>\/tasks<\/code> endpoint that stores and retrieves items using Redis. Configure a complete automated pipeline from commit to staging deployment.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Required Tasks<\/h3>\n\n\n\n<ol start=\"1\" class=\"wp-block-list\">\n<li><strong>Modify the Application:<\/strong> Add a <code>\/tasks<\/code> endpoint (supporting <code>GET<\/code> and <code>POST<\/code>) backed by Redis, plus unit tests covering valid and invalid payloads.<\/li>\n\n\n\n<li><strong>Manage Code in Git:<\/strong> Develop the feature on a dedicated branch (<code>feat\/tasks-endpoint<\/code>), open a pull request, and merge into <code>main<\/code>.<\/li>\n\n\n\n<li><strong>Automate Testing:<\/strong> Ensure unit tests and a multi-container integration test (API + Redis) execute automatically in CI.<\/li>\n\n\n\n<li><strong>Build and Harden the Image:<\/strong> Package the updated service using a non-root user and scan the image with Trivy.<\/li>\n\n\n\n<li><strong>Tag and Publish:<\/strong> Tag the verified image with both the Git commit SHA and semantic version (<code>1.2.0<\/code>), then push it to Docker Hub.<\/li>\n\n\n\n<li><strong>Deploy and Verify:<\/strong> Automatically deploy the updated container in your staging job and verify both <code>\/health<\/code> and <code>\/tasks<\/code>.<\/li>\n\n\n\n<li><strong>Document the Workflow:<\/strong> Write a clear <code>README.md<\/code> explaining prerequisites, local Docker Compose usage, required CI secrets, and rollback steps.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">Deliverables and Success Criteria<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Deliverables:<\/strong> A public GitHub repository containing application code, tests, hardened <code>Dockerfile<\/code>, <code>compose.yaml<\/code>, <code>.github\/workflows\/ci-cd.yml<\/code>, and <code>README.md<\/code>, alongside published versioned tags on Docker Hub.<\/li>\n\n\n\n<li><strong>Success Criteria:<\/strong> Pushing a broken test intentionally fails the pipeline before <code>docker push<\/code> runs; fixing the test turns the entire workflow green, publishes the SHA-tagged image to Docker Hub, and passes post-deployment HTTP verification.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What Learners Should Understand After Completing the Labs<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Working through these ten exercises builds practical competence across the core pillars of modern container delivery:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Containerization Fundamentals:<\/strong> Writing clean, cache-friendly <code>Dockerfile<\/code> definitions with minimal base images and non-root execution.<\/li>\n\n\n\n<li><strong>Container Lifecycle Management:<\/strong> Building, running, inspecting logs, debugging port bindings, and cleaning up containers reliably.<\/li>\n\n\n\n<li><strong>Source-Driven Automation:<\/strong> Structuring Git repositories and branches so every pipeline execution maps to an auditable commit.<\/li>\n\n\n\n<li><strong>Automated Quality Gates:<\/strong> Combining fast unit tests, live container health probes, and vulnerability scans to stop broken or insecure builds early.<\/li>\n\n\n\n<li><strong>Artifact Management:<\/strong> Tagging images deterministically with commit hashes and securely authenticating against container registries.<\/li>\n\n\n\n<li><strong>Multi-Service Orchestration:<\/strong> Coordinating application containers, databases, networks, and health dependencies with Docker Compose.<\/li>\n\n\n\n<li><strong>Deployment Reliability:<\/strong> Replacing running containers safely, verifying post-deploy health, and diagnosing failures methodically.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion: Turn Docker Practice Into a Repeatable CI\/CD Workflow<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Mastering CI\/CD does not require memorizing every flag or YAML keyword on day one. Breaking the delivery lifecycle into small, verifiable labs\u2014containerizing an app, running tests in isolation, tagging images deterministically, and automating health checks\u2014shows how each stage protects the next. When every commit passes through automated tests, security scans, and versioned registry builds, deployments stop feeling like risky manual events and become routine engineering tasks. Take the final challenge further by experimenting with multi-stage Docker builds to shrink image sizes even more, adding automated rollback scripts when health checks fail, or deploying your Docker Hub images onto a managed cloud container service or Kubernetes cluster.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Reading about continuous integration and continuous delivery only takes you so far. Real confidence in DevOps comes from wiring together source control, automated tests, container builds, and deployment scripts until&hellip;<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2302","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/posts\/2302","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/comments?post=2302"}],"version-history":[{"count":1,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/posts\/2302\/revisions"}],"predecessor-version":[{"id":2304,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/posts\/2302\/revisions\/2304"}],"wp:attachment":[{"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/media?parent=2302"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/categories?post=2302"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devopsschool.org\/blog\/wp-json\/wp\/v2\/tags?post=2302"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}