Docker-Compose is not downloading the specific version of PHP and Nginx that I want. I want the version “php:8.4.5-fpm” and it only downloads the “latest” version. I tried several things, but I can’t get it to download the specific image, it only downloads the “latest” image.
docker-compose
version: "3.9"
services:
nginx:
build:
context: ../nginx # Caminho para a pasta Nginx (relativo à pasta docker-compose)
ports:
- "80:80"
volumes:
- ../app:/var/www/html # Monta a pasta app como /var/www/html (relativo à pasta docker-compose)
depends_on:
- php
networks:
- laravel-network
php:
build:
context: ../php # Caminho para a pasta PHP (relativo à pasta docker-compose)
expose:
- 9000
volumes:
- ../app:/var/www/html # Monta a pasta app como /var/www/html (relativo à pasta docker-compose)
depends_on:
- db
networks:
- laravel-network
db:
image: mariadb:11.7.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: laravel
MYSQL_USER: laravel
MYSQL_PASSWORD: laravel
volumes:
- db_data:/var/lib/mysql
networks:
- laravel-network
phpmyadmin:
image: phpmyadmin:latest
ports:
- "8080:80"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: root
depends_on:
- db
networks:
- laravel-network
volumes:
db_data:
networks:
laravel-network:
driver: bridge
Dockerfile PHP
FROM bitnami/php-fpm:8.4.6
# Definir diretório de trabalho
WORKDIR /var/www/html
# Instalar dependências do sistema
RUN apt-get update && apt-get install -y \
build-essential \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
unzip \
git \
curl \
libzip-dev \
libonig-dev \
libxml2-dev \
&& apt-get clean && rm -rf /var/lib/apt/lists/*
# Instalar extensões PHP necessárias para o Laravel
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl soap
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install gd
# Instalar o Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Criar usuário para a aplicação Laravel
RUN groupadd -g 1000 www && useradd -u 1000 -ms /bin/bash -g www www
# Copiar o código da aplicação
COPY --chown=www:www . /var/www/html
# Alterar usuário
USER www
# Expor a porta 9000 para o PHP-FPM
EXPOSE 9000
CMD ["php-fpm"]
Dockerfile Nginx
FROM nginx:1.27.3
# Copiar a configuração do Nginx
COPY default.conf /etc/nginx/conf.d/default.conf
A Dockerfile doesn’t do anything, it is just a description of the image you want to build. It is not clear how you build that image, but if you already ran the project once using docker compose up -d, images will not be rebuilt, so if you had the latest images, nothing will change until you add --build like:
docker compose up -d --build
If it doesn’t help, please, explain how you build the image exactly and how you test the versions.
You will need to explain better what you are doing, otherwise I can only say what I already wrote in my previous post. Including the question at the end.
If you didn’t udnerstand my previous message, please, share which part was not clear.
in your PHP Dockerfile I see FROM bitnami/php-fpm:8.4.6, is this image contained in docker image ls
? Can you please provide the output of docker image ls
Recent image builders don’t tag the base image layer, so even if the layer is there, it won’t be shown in the output of docker image ls unless buildkit was disabled to use the legacy builder. It doesn’t mean the image layers were not downloaded, they were just not tagged, but I don’t think that is the issue here.
I’m trying to create a stack to study and learn Laravel. I want to download specific images. At this moment, I want to use this image with this exact version, but Docker always pulls the latest version instead.
vini@DESKTOP-K2QIPHU:/mnt/c/Docker-
Localhost/centraldocavaco$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
centraldocavaco-php latest 361b56c91a3c 2 minutes ago 799MB
mariadb 11.7.2 9f3d79eba61e 2 months ago 328MB
phpmyadmin latest 7a9597477072 3 months ago 570MB
Dockerfile
FROM serversideup/php:8.4.6-fpm-nginx
WORKDIR /app
# Usar o usuário root para instalar pacotes
USER root
# Instalar dependências necessárias e o Node.js
RUN apt-get update && apt-get install -y curl gnupg unzip zip git && \
curl -fsSL https://deb.nodesource.com/setup_22.x | bash - && \
apt-get install -y nodejs && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Definir o PATH explicitamente (por precaução)
ENV PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
# Definir o PATH corretamente no Dockerfile
ENV PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/sbin"
# Definir o PATH explicitamente
ENV PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/composer/vendor/bin"
# Retornar ao usuário padrão
USER www-data
I hope @bluepuma77’s explanation already made it clear, but since you have not responded yet, let me explain it from a different angle.
Just because you put a sheet on the bed, it doesn’t mean the bed is missing. It is under the sheet, and the image you define in the Dockerfile is under you changes. When you build your own image, it doesn’t mean you change the original image. You can never change an existing image. You use the chosen image as a base, and add new layers to it as bluepuma77 explained. The base image and your added layers together will be a new image. And how that new image is tagged (what version tag it gets) is up to you.
Docker Compose will automatically name your image and the full image name will include the project name and service name as well with “latest” as version tag. It is irrelevant as the whole image name was autogenerated.
If you want the original version to be part of your new image name, you can set it manually