Sure, here is the final Docker configuration for a Symfony 7.0 project with PHP 8.2, MySQL, Adminer, and FrankenPHP, including the necessary PHP extensions and a command for database creation.
First, the Dockerfile
:
# Dockerfile
FROM php:8.2-fpm
# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# Install necessary PHP extensions
RUN apt-get update && apt-get install -y \
libicu-dev \
libzip-dev \
zlib1g-dev \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
libxml2-dev \
libonig-dev \
libxslt1-dev
RUN docker-php-ext-configure gd --with-freetype --with-jpeg
RUN docker-php-ext-install -j$(nproc) gd
RUN docker-php-ext-install pdo_mysql
RUN docker-php-ext-install zip
RUN docker-php-ext-install intl
RUN docker-php-ext-install soap
RUN docker-php-ext-install xsl
RUN docker-php-ext-install sockets
RUN docker-php-ext-install bcmath
RUN docker-php-ext-install ctype
RUN docker-php-ext-install iconv
RUN docker-php-ext-install session
RUN docker-php-ext-install simplexml
RUN docker-php-ext-install tokenizer
# Install Symfony CLI
RUN curl -sS https://get.symfony.com/cli/installer | bash
RUN mv /root/.symfony/bin/symfony /usr/local/bin/symfony
WORKDIR /var/www/html
# Check if Symfony project is already created
RUN if [ ! -f ./composer.json ]; then symfony new my_project_name --full; fi
Next, the docker-compose.yml
file:
# docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
dockerfile: Dockerfile
volumes:
- .:/var/www/html
depends_on:
- db
db:
image: mysql:8.0
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: symfony
MYSQL_USER: symfony
MYSQL_PASSWORD: symfony
volumes:
- ./create_db.sql:/docker-entrypoint-initdb.d/create_db.sql
adminer:
image: adminer
ports:
- 8080:8080
depends_on:
- db
frankenphp:
image: frankenphp:latest
volumes:
- .:/var/www/html
ports:
- 9000:9000
depends_on:
- app
And the create_db.sql
script:
CREATE DATABASE IF NOT EXISTS symfony;
GRANT ALL PRIVILEGES ON symfony.* TO 'symfony'@'%' IDENTIFIED BY 'symfony';
FLUSH PRIVILEGES;
To create a new Symfony project, you can run the following command:
docker-compose run --rm app symfony new my_project_name --full
Replace my_project_name
with the name of your project.
To start the project, use the following command:
docker-compose up -d
This will start the containers in the background.
For the server configuration, you can use the FrankenPHP server. You can start it with the following command:
docker-compose exec frankenphp php -S 0.0.0.0:9000 -t public
Please note that you might need to adjust the PHP version in the Dockerfile and the MySQL version in the docker-compose file according to your project requirements. Also, don't forget to replace the database credentials in the docker-compose file with your actual credentials.