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
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
- Inside this folder create a new file
- Open the
Dockerfileand 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 --with-freetype --with-jpeg \ && docker-php-ext-install pdo_mysql zip gd RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
- Save and close the file.
Login to your Docker Hub account using the command
docker login. This command will ask for your credentials, and if all goes well, then you will get a success message
Build the docker image using the following command:
docker image build --platform linux/amd64 -t foobar/custom-cicd-php-8-cli:1.0.0 ./
In the above command:
foobarshould be replaced with your Docker Hub account username.
custom-cicd-php-8-cliis the name of the image, which can be changed to anything.
1.0.0is the tag version
NOTE: This command can take up to 45 minutes, as
grpc take quite a long time to install.
- Once build is successfully finished, you can push the image to your Docker Hub account using the following command:
docker push foobar/custom-cicd-php-8-cli:1.0.0
Upon successful push, confirm the changes in Docker Hub account.
You can delete your local docker image(s) by following these steps:
docker imagesto list the images on your local machine.
- From the list, copy the Image ID for your docker image that you want to delete.
docker rmi [Image ID]
- This command should delete the docker image with provided
Once everything is ready, now you can use this custom image in your Bitbucket pipeline and test your pipeline for build time.
Top comments (0)