@@ -18,37 +18,37 @@ Change the database image to use MySQL instead of PostgreSQL in `compose.yaml`:
18
18
<!-- markdownlint-disable MD013 -->
19
19
20
20
``` 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 ###
46
46
```
47
47
48
48
<!-- markdownlint-enable MD013 -->
49
49
50
50
Depending 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 ` :
52
52
53
53
``` yaml
54
54
DATABASE_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:
57
57
Since we changed the port, we also have to define this in the ` compose.override.yaml`:
58
58
59
59
` ` ` 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 ###
66
66
` ` `
67
67
68
68
Last but not least, we need to install the MySQL driver in `Dockerfile` :
69
69
70
70
` ` ` diff
71
- ###> doctrine/doctrine-bundle ###
71
+ ###> doctrine/doctrine-bundle ###
72
72
-RUN install-php-extensions pdo_pgsql
73
73
+RUN install-php-extensions pdo_mysql
74
- ###< doctrine/doctrine-bundle ###
74
+ ###< doctrine/doctrine-bundle ###
75
75
` ` `
76
76
77
77
# # Change Environment
0 commit comments