Optimizing Bitbucket Pipelines with Custom Docker Images

Ibrar Hussain
2 min readFeb 16, 2023

In this article, we will discuss the process of customizing an existing Docker Hub image, installing the required libraries and packages, building the new image, and pushing it to your Docker Hub account.

Suppose your project requires the Docker Hub image php:8.0.26-cli for your Bitbucket pipeline, but the installation of required libraries and packages, such as composer, git, curl, rsync, zip, mysql-client, gd, and grpc, is taking too long. In such a situation, you need to create a custom image and pre-install all the required packages, which will reduce the pipeline build time.

Here are the steps to create a custom Docker image:

  1. Make sure that you have installed Docker Client, if not, then you need to install it first.
  2. Create a new folder foo-custom-image.
  3. Inside this folder create a new file Dockerfile.
  4. Open the Dockerfile and add the following:
From php:8.0.26-cli

RUN apt-get update && apt-get install -qy \
unzip \
git \
curl \
rsync \
libmcrypt-dev \
libzip-dev \
zip \
default-mysql-client \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
zlib1g-dev

RUN curl -sSLf \
-o /usr/local/bin/install-php-extensions \
https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions && \
chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions grpc-1.45.0

RUN docker-php-ext-configure gd…

--

--

Ibrar Hussain

I am a full stack web developer with experience working on Laravel and Vue. I am passionate about exploring and learning new technologies in the field.