I'm learning to run codeigniter 4 in docker, but I have trouble connecting between codeigniter4 and databses.
an error occurred when I ran the command 'php spark migrate'
Code:
# php spark migrate
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2021-01-20 10:01:02am
Running all new migrations...
An uncaught Exception was encountered
Type: CodeIgniter\Database\Exceptions\DatabaseException
Message: Unable to connect to the database.
Filename: /var/www/html/system/Database/BaseConnection.php
Line Number: 425
Backtrace:
here's my configuration file
docker-compose.yml
Code:
services:
webService:
image: "ci4-image"
container_name: ws_host
ports:
- "80:80"
volumes:
- "./codeigniter4:/var/www/html"
networks:
WS_network: null
depends_on:
- webService_db
webService_db:
image: mysql:5.6
container_name: webService_db
ports:
- "3307:3306"
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ws_database
MYSQL_USER: ws_user
MYSQL_PASSWORD: ws_password
networks:
WS_network: null
# depends_on:
# - webService
networks:
WS_network: null
database.php
Code:
public $default = [
'DSN' => '',
'hostname' => 'webService_db:3307',
'username' => 'ws_user',
'password' => 'ws_password',
'database' => 'ws_database',
'DBDriver' => 'MySQLi',
'DBPrefix' => '',
'pConnect' => false,
'DBDebug' => (ENVIRONMENT !== 'production'),
'cacheOn' => false,
'cacheDir' => '',
'charset' => 'utf8',
'DBCollat' => 'utf8_general_ci',
'swapPre' => '',
'encrypt' => false,
'compress' => false,
'strictOn' => false,
'failover' => [],
'port' => '',
];