I'm new to docker/docker-compose. I'm trying to connect 2 containers which are the CodeIgniter application and MySQL. I can't seems to solve the 'mysqli::real_connect(): (HY000/2002): Connection refused' issue on my web app. I was able to ping from inside the container to the other and vice versa.
This is my docker-compose.yml file:
version: '3'
services:
  web:
    container_name: ciblog
    build: .
    links: 
      - db
    depends_on:
      - db
    ports:
      - '80:80'
    volumes: 
      - .:/var/www/html/
  db:
    container_name: mysql
    image: mysql:latest
    ports:
      - '3306:3306'
    environment:
      MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
      MYSQL_USER: root
      MYSQL_DATABASE: ciblog
    volumes:
      - ./assets/sql/ciblog.sql:/docker-entrypoint-initdb.d/ciblog.sql
Dockerfile:
FROM php:7.0-apache
RUN apt-get update && \
    apt-get install -y libfreetype6-dev libjpeg62-turbo-dev && \
    docker-php-ext-install mysqli && \
    docker-php-ext-install mbstring && \
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/  &&  \
    docker-php-ext-install gd
RUN a2enmod rewrite
RUN service apache2 restart
Here's my database.php configuration:
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
    'dsn'   => '',
    'dbport' => '3306',
    'hostname' => 'db',
    'username' => 'root',
    'password' => '',
    'database' => 'ciblog',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => FALSE,
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);
Could anyone please help me identify the issue? Thank you in advance. Here's my GitHub repository in case you want to see the files: https://github.com/josephsim/docker-ciblog
 
     
     
    