Created on 16th May 2024
•
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.
Working on the container provisioning engine, I encountered a few interesting hurdles that pushed me to refine my approach:
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.
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.
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.
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.