0
0
Dockerdevops~5 mins

Pushing images from CI in Docker - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Pushing images from CI
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

Look for repeated steps that affect total time.

  • Primary operation: The docker push command inside the loop.
  • How many times: It runs once for each image, here 3 times.
How Execution Grows With Input

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)
1010 pushes
100100 pushes
10001000 pushes

Pattern observation: Doubling the number of images doubles the total push time.

Final Time Complexity

Time Complexity: O(n)

This means the total time grows linearly with the number of images pushed.

Common Mistake

[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.

Interview Connect

Understanding how CI tasks scale helps you design pipelines that run efficiently and predictably as projects grow.

Self-Check

What if we pushed images in parallel instead of one by one? How would the time complexity change?