Bonjour à tous.
J'ai créé un projet avec symfony6. Je souhaite dockeriser ce projet.
À la racine du dossier qui contient tout le projet (src, public, .env, var, templates etc) j'ai ajouté un fichier docker-compose.yml et un dossier docker dans lequel j'ai trois fichiers (Dockerfile, apache.conf, docker.sh)
le dockerfile:
FROM php:8.1-apache
# Installe, rend exécutable et exécute le programme afin d'installer les extensions PHP
ADD https://github.com/mlocati/docker-ph...php-extensions /usr/local/bin/
RUN chmod +x /usr/local/bin/install-php-extensions && \
install-php-extensions pdo_pgsql intl
#Télécharge composer.phar, desactive tls et installe composer dans le répertoire
RUN curl -sSk https://getcomposer.org/installer | php -- --disable-tls && \
mv composer.phar /usr/local/bin/composer
#Installe nodeJS afin de disposer des commandes npm
RUN apt update && apt install -yqq nodejs npm
COPY . /var/www/
COPY ./docker/apache.conf /etc/apache2/sites-available/000-default.conf
RUN cd /var/www && \
composer install && \
npm install --force && \
npm run build
#Redéfini le répertoire de travail (pour la console)
WORKDIR /var/www/
ENTRYPOINT ["bash", "./docker/docker.sh"]
EXPOSE 80
Le apache.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot /var/www/public
DirectoryIndex /index.php
<Directory /var/www/public>
AllowOverride None
Order Allow,Deny
Allow from All
FallbackResource /index.php
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
Le docker.sh (lance des commandes)
php bin/console d:m:m --no-interaction
php bin/console app:create-user demo@demo.com password
exec apache2-foreground
Le docker-compose.yml
version: '3'
services:
database:
image: postgres:${POSTGRES_VERSION:-13}-alpine
environment:
POSTGRES_DB: ${POSTGRES_DB:-app}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-ChangeMe}
POSTGRES_USER: ${POSTGRES_USER:-symfony}
volumes:
- db-data:/var/lib/postgresql/data:rw
app:
image: myimage
ports:
- "8080:80"
environment:
DATABASE_URL: postgres://${POSTGRES_USER:-symfony}:${POSTGRES_PASSWORD:-ChangeMe}@database:5432/${POSTGRES_DB:-app}
volumes:
db-data:
L'image est bien construite docker build . -f ./docker/Dockerfile -t myimage
Les containers sont bien lancés: docker compose up -d
En testant : localhost:8080/ j'ai une erreur:
The stream or file "/var/www/var/log/dev.log" could not be opened in append mode: Failed to open stream: Permission denied
The exception occurred while attempting to log: User Deprecated: Method "Symfony\Component\HttpKernel\Bundle\Bundle::build()" might add "void" as a native return type declaration in the future. Do the same in child class "Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle" now to avoid errors or add an explicit @return annotation to suppress this message.
Context: {"exception":{}}
Pouvez-vous m'aider? Je suis ultra débutant. Merci à ceux qui prendront le temps de m'aider.
Partager