Skip to main content
In this lesson, we demonstrate how to use rebasing to update the operating system base layer without rebuilding the subsequent layers, including the application layer. This approach is especially useful when addressing security vulnerabilities, installing new libraries, or upgrading the underlying distribution—all without the overhead of a full rebuild.

Step 1: Verify Your Application Image

Before rebasing, ensure that your application image is built and available in Docker. Run the following command to list your Docker images:
To inspect the image details, including the buildpacks used and the runtime image, execute:
The output will include detailed information similar to:
The output confirms that the current base (runtime) image is run-base:v1.
The pack inspect command provides critical insight into your image’s structure. Verifying that your image is rebasable is an important prerequisite before proceeding.

Step 2: Create a New Base Image

Suppose you need to update the base image—for instance, to switch from Ubuntu Jammy to Ubuntu Focal and install additional packages. First, modify your Dockerfile for the runtime image.

Original Dockerfile (Ubuntu Jammy)

Updated Dockerfile (Ubuntu Focal)

Step 3: Build the New Base Image

Before building, verify that your containers are running correctly by checking them with:
Now, navigate to the appropriate directory (for example, the “builder” directory) and build the new base image:
Ensure you are in the correct directory containing the updated Dockerfile before running the build command.

Step 4: Rebase the Application Image

After successfully building the new base image (run-base:v2), update the application image using rebasing with the following command:
This command replaces the original runtime image with run-base:v2 without rebuilding the other layers of your image.

Step 5: Verify the Updated Base Image

To confirm that rebasing was successful, inspect your application image again:
You should see output reflecting the updated base image, similar to:
This demonstrates that only the base image layer was replaced, while the application layer remains unchanged.
Rebasing provides an efficient workflow for updating critical components like the operating system layer without incurring the overhead of a full image rebuild.

Watch Video