I use Ubuntu as base for my docker images. I have an apt-get update at the start of my Dockerfile to ensure that I get the latest packages. However, the update proves to be time consuming, and really slows down the build. Is there any way I can speed it up?

Short Answer

Use Ubuntu mirrors closest to your region (In the Philippines, that’s In your Dockerfile, add this:

RUN sed --in-place --regexp-extended \
      "s/(archive\.ubuntu\.com)/" /etc/apt/sources.list && \
    sed --in-place --regexp-extended \ 
      "s/(security\.ubuntu\.com)/" /etc/apt/sources.list && \
    apt-get update 

Long Answer

I love developing in Ubuntu. I use it as my development enviroment (Ubuntu VirtualBox on MacOS). I use Ubuntu-based docker containers for both the staging and production environment to ensure that the environment in my development laptop is exactly the same as those environments, thus avoiding the “It works on my machine” syndrome.


One important step in any container image build is to get the latest package updates. Unfortunately, this may be also the part where it takes most time. One relatively easy fix for this is to find an Ubuntu mirror closest to where you are building your images.

An extensive list of Ubuntu mirrors all over the world can be found here.

A sample Dockerfile that demonstrates how you can change to your Ubuntu mirror can be found here.


Ardee Aram

Cloud Architect. Experienced Node.js Developer. Husband. Father. Problem Solver. Eternal Student of Life.