Blog
Engineering
Community
6
minutes

3 Tips to Improve Your Dockerfile Build Time

Building Docker images efficiently is crucial for developers and organizations seeking streamlined development and deployment processes, and it’s a real topic for the 50k developers on Qovery; a few weeks ago, a topic was even open on our forum about it. In this article, we will explore three valuable tips gathered along the way to improve the build time of your Dockerfiles, allowing you to optimize your workflow and save valuable time.
Albane Tonnellier
Product Marketing Manager
Summary
Twitter icon
linkedin icon

What is a Dockerfile?

Before we dive into the tips, let's quickly recap what a Dockerfile is. A Dockerfile is a text file that contains instructions on how to build a container image. It's like a recipe that tells Docker what to do step-by-step to create the artifact you need for your application.

When do you Need a Dockerfile?

If you’re deploying to the cloud or planning to, using Qovery or not, having a Dockerfile becomes (almost) essential. Qovery relies on Docker to build and run your application in a consistent and isolated environment. With a Dockerfile, you can define all the dependencies, configurations, and steps needed to set up your application within a Docker container.

Because Qovery got you covered, we even wrote a guide on How to write a Dockerfile in case it’s your first time.

If you're curious about why using Docker over other options like buildpacks, you can check out this article here for more information.

How Long Should a Docker build take?

The duration of a Docker build can vary depending on various factors, such as the complexity of your application, the size of the image, and the resources available on your machine. It's important to keep an eye on the build time to ensure efficient development and deployment processes. Fortunately, there are some tips you can follow to improve the buildtime of your Dockerfiles.

3 Tips to Improve Your Build Time

1. Create an intermediate image

Consider creating an intermediate image that you can store somewhere. This version should contain an already built version of your code. Even if it's not 100% up to date, using this intermediate image can save you time by avoiding recompiling already built libraries and dependencies. While it may not be the most convenient approach, it gets the job done efficiently.

# Stage 1: Build the code
FROM as builder

# Copy your source code to the container
COPY . /app

# Build your code
RUN

# Stage 2: Create the intermediate image
FROM

# Copy the already built code from the builder stage
COPY --from=builder /app /app

# Set up any additional dependencies or configurations

# Define the command to run your application
CMD [""]

In this example, the code is divided into two stages. The first stage, builder, is responsible for building your code using the specified build commands. The result is stored in the /app directory within the builder stage.

In the second stage, a new base image is used. The already built code is copied from the builder stage into the new image's /app directory. This eliminates the need to rebuild the code, as the intermediate image contains the compiled code. Any additional dependencies or configurations can be set up in this stage.

Finally, the command to run your application is defined using the CMD directive.

Remember to replace <base_image>, <build_commands>, and <command_to_run_your_app> with the appropriate values for your specific project.

2. Utilize faster CI services

By leveraging Docker caching and modern CI tools like GitHub Actions or CircleCI, you can significantly reduce build time for containerized applications. These CI platforms offer additional features and optimizations to streamline your development and deployment workflow. Allowing Qovery to deploy containers built via your CI gets your deployment to the next efficiency and speed level.

# .github/workflows/build.yml (for GitHub Actions)
# or
# .circleci/config.yml (for CircleCI)

name: Build and Deploy

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Build and Test
run: |
# Build and test your code here



- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /var/lib/docker
key: ${{ runner.os }}-docker-${{ hashFiles('**/Dockerfile') }}

- name: Build Docker image
run: |
# Build your Docker image here
docker build -t your-image-name .

- name: Push Docker image to registry
run: |
# Push your Docker image to a registry
docker push your-registry/your-image-name

deploy:
needs: build

runs-on: ubuntu-latest

steps:
- name: Install Qovery CLI
run: |
# Install the Qovery CLI
curl -sSL | sh

- name: Configure Qovery
run: |
# Configure Qovery with your credentials and project information
qovery auth login --email your-email --password your-password
qovery project select --name your-project-name

- name: Deploy to Qovery
run: |
# Deploy your application to Qovery
qovery run deploy

This example assumes you are using either GitHub Actions or CircleCI for your CI/CD pipeline. The code is divided into two jobs: build and deploy.

In the build job, the code is checked out, built, and tested using the specified build and test commands. Docker caching is then utilized to cache the Docker layers, improving build speed by reusing cached layers when possible. The Docker image is built and pushed to a registry.

In the deploy job, the Qovery CLI is installed and configured with your credentials and project information. Finally, the application is deployed to Qovery using the qovery run deploy command.

Remember to replace <build_commands>, <test_commands>, your-image-name, your-registry, your-email, your-password, and your-project-name with the appropriate values for your specific project.

3. Leverage pre-built components

If you already have a CI pipeline set up with tests and other processes, chances are you have already built some components you need. In this case, you can save a lot of time by copying the already built artifacts into a container, pushing it to a repository, and then using containers on Qovery instead of rebuilding the entire application. This way, you can leverage the work you've already done and significantly reduce your build time.

# Stage 1: Build and test your components
FROM as builder

# Copy and build your components
COPY . /app/components
RUN

# Run tests
RUN

# Stage 2: Create the final container
FROM qovery/

# Copy the pre-built components from the builder stage
COPY --from=builder /app/components /app/components

# Set up any additional dependencies or configurations

# Define the command to run your application
CMD [""]

In this example, the code is divided into two stages. The first stage, builder, is responsible for building and testing the components. The components are copied into the /app/components directory and built using the specified build commands. Tests are executed using the provided test commands.

In the second stage, a Qovery base image is used. The pre-built components from the builder stage are copied into the final container's /app/components directory. Any additional dependencies or configurations can be set up in this stage.

Finally, the command to run your application is defined using the CMD directive.

Remember to replace <base_image>, <build_commands>, <test_commands>, and <command_to_run_your_app> with the appropriate values for your specific project.

Wrapping Up

Optimizing the build time of your Dockerfiles can greatly improve your development workflow and deployment speed. By following these three tips, you can create a more efficient build process and save valuable time. Remember to experiment and find the best approach that suits your specific project and requirements, and when your Dockerfile is ready, you are all set for cloud deployment, why not try out Qovery!

Share on :
Twitter icon
linkedin icon
Tired of fighting your Kubernetes platform?
Qovery provides a unified Kubernetes control plane for cluster provisioning, security, and deployments - giving you an enterprise-grade platform without the DIY overhead.
See it in action

Suggested articles

DevOps
Kubernetes
 minutes
Top 10 Platform9 Alternatives: Best managed Kubernetes solutions for scale

Need a better way to manage on-prem Kubernetes? Review 10 alternatives to Platform9, categorized by "Infrastructure Ops" (Rancher) vs. "Developer Experience" (Qovery).

Mélanie Dallé
Senior Marketing Manager
DevOps
Kubernetes
 minutes
Top 10 Rafay alternatives for enterprise Kubernetes operations

Is Rafay's complexity slowing you down? Compare the top 10 Rafay alternatives for 2026. From fleet managers like Rancher to developer platforms like Qovery, find the balance between control and velocity.

Mélanie Dallé
Senior Marketing Manager
DevOps
Kubernetes
 minutes
Top 10 Spectro Cloud alternatives for multi-cluster fleet management

Don't just manage clusters. Modernize your stack. Compare Spectro Cloud vs. Qovery vs. Rancher to decide between "Fleet Operations" and "Developer Self-Service.

Mélanie Dallé
Senior Marketing Manager
DevOps
Kubernetes
 minutes
Top 10 VMware alternatives after the Broadcom acquisition

Hit by Broadcom's VMware price hikes? Compare the top 10 alternatives for 2026, from direct replacements like Proxmox and Nutanix to modernization platforms like Qovery.

Mélanie Dallé
Senior Marketing Manager
DevOps
Kubernetes
Platform Engineering
6
 minutes
10 Red Hat OpenShift alternatives to reduce licensing costs

Is OpenShift too expensive? Discover the best alternatives for 2026. Whether you need Developer Self-Service (Qovery) or Hybrid Cluster Ops (Rancher), find the right fit for your team.

Morgan Perry
Co-founder
Kubernetes
 minutes
Kubernetes management: Best practices for enterprise scaling and cost optimization

Master enterprise Kubernetes management in 2026. Learn best practices for security, FinOps, and reliability, and see how AI-agentic platforms simplify operations.

Mélanie Dallé
Senior Marketing Manager
Kubernetes
Platform Engineering
Infrastructure Management
 minutes
The top 3 OpenShift pains in 2026 (and how platform teams respond)

Is OpenShift becoming too expensive or complex for your team? Discover the top 3 OpenShift pain points; from the "pricing inversion" to vendor lock-in and see why agile platform teams are migrating to modular, developer-first alternatives like Qovery.

Mélanie Dallé
Senior Marketing Manager
AI
Qovery
3
 minutes
How Qovery uses Qovery to speed up its AI project

Discover how Qovery leverages its own platform to accelerate AI development. Learn how an AI specialist deployed a complex stack; including LLMs, QDrant, and KEDA - in just one day without needing deep DevOps or Kubernetes expertise. See how the "dogfooding" approach fuels innovation for our DevOps Copilot.

Romain Gérard
Staff Software Engineer

It’s time to change
the way you manage K8s

Turn Kubernetes into your strategic advantage with Qovery, automating the heavy lifting while you stay in control.