I'm building docker image with gitlab-CI with the next Dockerfile:
ARG BUILD_VERSION="prod"
FROM php:8.2.1-fpm as base
RUN apt-get update && apt-get install -y libicu-dev libonig-dev libcurl3-dev libxml2-dev ssh git nano mc \
&&docker-php-ext-install pdo_mysql mysqli mbstring curl intl xml \
&&apt-get clean && rm -rf /var/lib/apt/lists/*
WORKDIR /var/www/html
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
COPY ["php/conf.d/error_reporting.ini", "/php/conf.d/timezone.ini", "/usr/local/etc/php/conf.d/"]
FROM base AS version-prod
RUN composer update
FROM base AS version-dev
RUN pecl install xdebug && rm -rf /tmp/pear
COPY ["php/conf.d/xdebug.ini" , "/usr/local/etc/php/conf.d/"]
EXPOSE 22
FROM version-${BUILD_VERSION} AS current
# This select current version
FROM current
Corresponding gitlab-ci.yml is quite simple:
Build:
stage: build
image: docker:latest-git
services:
- docker:dind
before_script:
- docker info
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker pull $CI_REGISTfRY_IMAGE:php-latest || true
- docker build --cache-from $CI_REGISTRY_IMAGE:php-latest --tag $CI_REGISTRY_IMAGE:php-$CI_COMMIT_SHA --tag $CI_REGISTRY_IMAGE:php-latest -f ./Dockerfile .
- docker push $CI_REGISTRY_IMAGE:php-latest
- docker push $CI_REGISTRY_IMAGE:php-$CI_COMMIT_SHA
But when i deploy the container on this image, there is no files php/conf.d/error_reporting.ini
and /php/conf.d/timezone.ini
in the container present.
Why is that happening?
The issue arises from how the COPY instruction is used in the Dockerfile. The COPY instruction copies files from the build context into the image. When I specify a relative path in the COPY command, it assumes that these files are present in the directory from which docker build is run.
In the Dockerfile, I have:
COPY ["php/conf.d/error_reporting.ini", "/php/conf.d/timezone.ini", "/usr/local/etc/php/conf.d/"]
This command is attempting to copy php/conf.d/error_reporting.ini and php/conf.d/timezone.ini from your build context into the /usr/local/etc/php/conf.d/ directory inside the image. If these files are not present in the build context (the directory where you run docker build), they won't be copied into the image.
To resolve this issue, ensure that php/conf.d/error_reporting.ini and php/conf.d/timezone.ini are present in the correct directory within your build context. The build context is the directory (and its subdirectories) from which the docker build command are run. If the files are in a different directory or not properly placed in the context, they won't be found and thus won't be copied.