C

Container Provisioning Engine

API service to provision, manage, and expose Docker containers.

48

Created on 16th May 2024

C

Container Provisioning Engine

API service to provision, manage, and expose Docker containers.

The problem Container Provisioning Engine solves

An API service to provision, manage, and expose Docker containers — written in Go and uses the Docker SDK for container management, golang channels and goroutines for concurrency, and Traefik as a reverse proxy to expose the containers.

Features

  • Provisioning of Docker containers from a specified image tag.
  • Support for pulling images from authenticated registries using a username and password.
  • Exposing provisioned containers on a subdomain with a Let's Encrypt SSL certificate.
  • An async task queue system for managing deployment tasks.

Challenges I ran into

Working on the container provisioning engine, I encountered a few interesting hurdles that pushed me to refine my approach:

Graceful Shutdown & Concurrency

Managing asynchronous tasks via goroutines and channels was tricky. Initially, the system didn’t shut down gracefully—background tasks continued processing despite a termination signal. Switching to a cancellation approach with Go’s context and adding proper timeouts ensured all tasks terminated safely.

Docker API Race Conditions

Simultaneous operations on containers sometimes led to race conditions, particularly during removal and provisioning. Implementing robust error handling and adding state verifications (plus some strategic retries) minimized conflicts and made the process much more reliable.

Dynamic Port Allocation:

Dynamically assigning ports to containers occasionally resulted in conflicts when multiple deployments were in progress. Centralizing the port assignment logic and synchronizing port allocation helped avoid these clashes and improved overall stability.

Traefik Reverse Proxy Configuration

Setting up proper Docker labels for Traefik, especially with SSL from Let’s Encrypt, required several iterations. Misconfiguration initially led to incorrect routing and SSL errors. Careful tweaking and testing in a staging environment eventually polished the setup.

These challenges not only enhanced the robustness of the system but also encouraged me to adopt more composable, functional programming patterns that make the code easier to understand and maintain.

Technologies used

Discussion

Builders also viewed

See more projects on Devfolio