@@ -18,37 +18,37 @@ Change the database image to use MySQL instead of PostgreSQL in `compose.yaml`:
1818<!-- markdownlint-disable MD013 -->
1919
2020``` diff
21- # ##> doctrine/doctrine-bundle ###
22- - image: postgres:${POSTGRES_VERSION:-16}-alpine
23- + image: mysql:${MYSQL_VERSION:-8}
24- environment:
25- - POSTGRES_DB: ${POSTGRES_DB:-app}
26- + MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
27- # You should definitely change the password in production
28- + MYSQL_RANDOM_ROOT_PASSWORD: "true"
29- - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
30- + MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
31- - POSTGRES_USER: ${POSTGRES_USER:-app}
32- + MYSQL_USER: ${MYSQL_USER:-app}
33- healthcheck:
34- - test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
35- + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
36- timeout: 5s
37- retries: 5
38- start_period: 60s
39- volumes:
40- - - database_data:/var/lib/postgresql/data:rw
41- + - database_data:/var/lib/mysql:rw
42- # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
43- - # - ./docker/db/data:/var/lib/postgresql/data:rw
44- + # - ./docker/db/data:/var/lib/mysql:rw
45- # ##< doctrine/doctrine-bundle ###
21+ ###> doctrine/doctrine-bundle ###
22+ - image: postgres:${POSTGRES_VERSION:-16}-alpine
23+ + image: mysql:${MYSQL_VERSION:-8}
24+ environment:
25+ - POSTGRES_DB: ${POSTGRES_DB:-app}
26+ + MYSQL_DATABASE: ${MYSQL_DATABASE:-app}
27+ # You should definitely change the password in production
28+ + MYSQL_RANDOM_ROOT_PASSWORD: "true"
29+ - POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-!ChangeMe!}
30+ + MYSQL_PASSWORD: ${MYSQL_PASSWORD:-!ChangeMe!}
31+ - POSTGRES_USER: ${POSTGRES_USER:-app}
32+ + MYSQL_USER: ${MYSQL_USER:-app}
33+ healthcheck:
34+ - test: ["CMD", "pg_isready", "-d", "${POSTGRES_DB:-app}", "-U", "${POSTGRES_USER:-app}"]
35+ + test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
36+ timeout: 5s
37+ retries: 5
38+ start_period: 60s
39+ volumes:
40+ - - database_data:/var/lib/postgresql/data:rw
41+ + - database_data:/var/lib/mysql:rw
42+ # You may use a bind-mounted host directory instead, so that it is harder to accidentally remove the volume and lose all your data!
43+ - # - ./docker/db/data:/var/lib/postgresql/data:rw
44+ + # - ./docker/db/data:/var/lib/mysql:rw
45+ ###< doctrine/doctrine-bundle ###
4646```
4747
4848<!-- markdownlint-enable MD013 -->
4949
5050Depending on the database configuration,
51- modify the environment in the same file at ` services.php.environment.DATABASE_URL `
51+ modify the environment in the same file at ` services.php.environment.DATABASE_URL ` :
5252
5353``` yaml
5454DATABASE_URL : mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:3306/${MYSQL_DATABASE:-app}?serverVersion=${MYSQL_VERSION:-8}&charset=${MYSQL_CHARSET:-utf8mb4}
@@ -57,21 +57,21 @@ DATABASE_URL: mysql://${MYSQL_USER:-app}:${MYSQL_PASSWORD:-!ChangeMe!}@database:
5757Since we changed the port, we also have to define this in the ` compose.override.yaml`:
5858
5959` ` ` diff
60- ###> doctrine/doctrine-bundle ###
61- database:
62- ports:
63- - - "5432"
64- + - "3306"
65- ###< doctrine/doctrine-bundle ###
60+ ###> doctrine/doctrine-bundle ###
61+ database:
62+ ports:
63+ - - "5432"
64+ + - "3306"
65+ ###< doctrine/doctrine-bundle ###
6666` ` `
6767
6868Last but not least, we need to install the MySQL driver in `Dockerfile` :
6969
7070` ` ` diff
71- ###> doctrine/doctrine-bundle ###
71+ ###> doctrine/doctrine-bundle ###
7272-RUN install-php-extensions pdo_pgsql
7373+RUN install-php-extensions pdo_mysql
74- ###< doctrine/doctrine-bundle ###
74+ ###< doctrine/doctrine-bundle ###
7575` ` `
7676
7777# # Change Environment
0 commit comments