06 / 06

What is the role of Docker in a GitOps workflow?

In a GitOps workflow, Docker serves as the essential containerization tool that packages applications into immutable, versioned images, acting as the primary artifact that flows from code commit to production deployment.

Docker plays a foundational role in GitOps by providing the mechanism to containerize applications, creating portable and consistent runtime environments. In a GitOps workflow, Git serves as the single source of truth for both application code and infrastructure configuration. Docker images become the immutable artifacts that are built, scanned, stored in registries, and ultimately deployed by GitOps operators like ArgoCD or Flux. The entire pipeline is driven by Git commits, with Docker images serving as the bridge between continuous integration and continuous delivery.

GitOps builds on the declarative infrastructure enabled by containerization. With Docker, you can describe your entire application stack in code, which can then be versioned in Git alongside your Kubernetes manifests. This creates a fully auditable, reproducible deployment process where every change is tracked and can be rolled back using standard Git operations.

Key Roles of Docker in GitOps
  1. 1

    Application Packaging: Docker packages applications with their dependencies into OCI-compliant container images, ensuring consistency across development, testing, and production environments. This packaging happens through Dockerfiles that define the exact runtime environment.

  2. 2

    Immutable Artifacts: Each Docker image built in CI becomes an immutable, versioned artifact with a unique tag (often using Git commit SHAs). This immutability is crucial for GitOps because it ensures that the artifact deployed to production is exactly the same one that passed testing.

  3. 3

    Registry Storage: Built images are pushed to container registries (Docker Hub, GitHub Container Registry, etc.), where they become available for deployment. The GitOps agent pulls these specific versions based on the image tags defined in Git-manifests.

  4. 4

    Declarative Configuration: Dockerfiles themselves are declarative specifications that can be stored in Git, making the entire build process part of the GitOps workflow. Any change to how the application is built goes through pull requests and code review.

  5. 5

    Multi-stage Builds: Docker multi-stage builds enable creating lean, secure production images by separating build and runtime dependencies, reducing attack surface and improving deployment speed.

GitOps Workflow Example with Docker

The separation of concerns in GitOps is critical: the CI pipeline builds and pushes Docker images, then updates the Git repository containing Kubernetes manifests with the new image tag. The GitOps agent running in the cluster continuously compares the desired state in Git with the live state, and pulls the new Docker image when a change is detected. This means the CI server never needs direct access to the production cluster, significantly improving security. Docker images become the secure, immutable payload that flows through this pipeline, with every version cryptographically linked to the source code that produced it.

Difficulty: 6/10
Topics: container image lifecycle, GitOps reconciliation, CI/CD integration

Scenario Questions

0-2 years experience
  1. 1

    If you have a Git repo with Kubernetes manifests, how would you use Docker to get a new version of an app into the cluster?

  2. 2

    What happens in the GitOps flow when a new Docker image is pushed to the registry?

  3. 3

    How would you verify that the Docker image tag in the manifest matches the image actually deployed?

2-5 years experience
  1. 1

    We updated a Dockerfile but the GitOps operator didn't roll out the change. Walk me through how you'd debug the issue.

  2. 2

    Explain the trade‑offs between building Docker images in the CI pipeline versus letting the GitOps system build them on demand.

  3. 3

    Why can using a mutable tag like 'latest' cause problems in a GitOps workflow?

5-8 years experience
  1. 1

    Design a GitOps pipeline that ensures every Docker image is scanned for vulnerabilities before it is reconciled to the cluster. What components would you add?

  2. 2

    At large scale, how do you manage storage and lifecycle of Docker images referenced by many GitOps repositories?

  3. 3

    If a Docker image is large and slows down GitOps sync, what architectural changes could mitigate the impact?

8+ years experience
  1. 1

    Our org wants to move from a monolithic Docker image strategy to per‑service images while keeping existing GitOps repos stable. How would you plan and execute that migration?

  2. 2

    Discuss the long‑term maintenance implications of tightly coupling Docker builds to GitOps manifests versus decoupling them via an artifact registry.

  3. 3

    How would you convince cross‑functional teams to adopt immutable Docker image tags in a GitOps environment, given legacy services and compliance constraints?

Follow-up Questions

  • What steps would you take if the image tag in Git doesn't exist in the registry?
  • How do you enforce immutability of Docker image tags in a GitOps pipeline?
  • Can you describe a case where Docker layer caching affected GitOps sync performance?