I'm building a Docker
Image for my Laravel
application but it's getting bigger than 1GB
.
This is the Dockerfile
:
#
# PHP Dependencies
#
FROM composer as vendor
COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install \
--ignore-platform-reqs \
--no-interaction \
--no-plugins \
--no-scripts \
--prefer-dist
#
# Application
#
FROM php:fpm-alpine
RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
curl \
libtool \
libxml2-dev \
&& apk add --no-cache \
curl \
git \
mysql-client \
&& pecl install redis \
&& docker-php-ext-install \
pdo \
pdo_mysql \
tokenizer \
bcmath \
opcache \
xml \
&& apk del -f .build-deps \
&& docker-php-ext-enable \
pdo_mysql \
redis
WORKDIR /var/www/html
COPY . /var/www/html
COPY --from=vendor /app/vendor/ /var/www/html/vendor/
COPY .env.staging /var/www/html/.env
RUN chown -R root:www-data .
EXPOSE 9000
CMD ["php-fpm"]
I use Vue
as front-end and Redis
as caching provider.
I am used to images around the 200-300 MBs but this is ridiculous.
What can I do to reduce the image size?
Thanks in advance.
Since
docker
filesystem isOverlayFS
, you need a special tool to dive into FS layers.There are many tools to explore images. For your case I'd suggest
wagoodman/dive
: A tool for exploring each layer in a docker imageAs you can see on the screenshot -
Layers
table hasSize
column.So, you can find - which layer of your
docker
image has the greatest contribution to the volume of the final image.