Pushing images from CI in Docker - Time & Space Complexity
When pushing Docker images from a Continuous Integration (CI) system, it's important to understand how the time taken grows as the image size or number of images increases.
We want to know how the push operation's time changes when we push more or bigger images.
Analyze the time complexity of the following Docker push commands in a CI pipeline.
# Tag the images
docker tag myapp:latest registry.example.com/myapp:latest
docker tag backend:latest registry.example.com/backend:latest
docker tag frontend:latest registry.example.com/frontend:latest
# Push the images to the registry
for image in myapp backend frontend; do
docker push registry.example.com/$image:latest
echo "$image pushed"
done
This snippet tags three images and then pushes them one by one to a remote registry.
Look for repeated steps that affect total time.
- Primary operation: The
docker pushcommand inside the loop. - How many times: It runs once for each image, here 3 times.
As the number of images to push increases, the total push time grows roughly in direct proportion.
| Input Size (n images) | Approx. Operations (push commands) |
|---|---|
| 10 | 10 pushes |
| 100 | 100 pushes |
| 1000 | 1000 pushes |
Pattern observation: Doubling the number of images doubles the total push time.
Time Complexity: O(n)
This means the total time grows linearly with the number of images pushed.
[X] Wrong: "Pushing multiple images at once takes the same time as pushing one image."
[OK] Correct: Each image push uploads data separately, so total time adds up with more images.
Understanding how CI tasks scale helps you design pipelines that run efficiently and predictably as projects grow.
What if we pushed images in parallel instead of one by one? How would the time complexity change?