I use Ubuntu as base for my docker images. I have an
apt-get updateat 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?
Use Ubuntu mirrors closest to your region (In the Philippines, that’s
mirror.pregi.net). In your Dockerfile, add this:
RUN sed --in-place --regexp-extended \ "s/(archive\.ubuntu\.com)/mirror.pregi.net/" /etc/apt/sources.list && \ sed --in-place --regexp-extended \ "s/(security\.ubuntu\.com)/mirror.pregi.net/" /etc/apt/sources.list && \ apt-get update
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
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.