Optimizing Bitbucket Pipelines with Custom Docker Images
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:
- Make sure that you have installed Docker Client, if not, then you need to install it first.
- Create a new folder
foo-custom-image
. - Inside this folder create a new file
Dockerfile
. - 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…