Can’t connect to mysql container using php

I have docker with three containers.

  1. Nginx(latest),
  2. Mysql(5.6),
  3. PHP(7.2-fpm).

When I trying to connect to database from php file I get error (Connection refused 2002). How I can solve it. Please help(

PHP code: 
$servername = "127.0.0.1";
$username = "root";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error . " " . mysqli_connect_errno());
}
echo "Connected successfully";

Output:

Connection failed: Connection refused 2002

PHP Dockerfile:

FROM php:7.2-fpm

RUN apt-get update && 
    apt-get install -y 
    git 
    curl 
    nano 
    libfreetype6-dev 
    libwebp-dev 
    libjpeg62-turbo-dev 
    libpng-dev 
    nano 
    libgmp-dev 
    libldap2-dev 
    netcat 
    sqlite3 
    libsqlite3-dev && 
    docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-webp-dir=/usr/include/  --with-jpeg-dir=/usr/include/ && 
    docker-php-ext-install gd pdo pdo_mysql pdo_sqlite zip gmp bcmath pcntl ldap sysvmsg exif mysqli

RUN apt-get update -y && 
    apt-get install -y libmcrypt-dev && 
    pecl install mcrypt-1.0.1 && 
    docker-php-ext-enable mcrypt

RUN chmod 777 -R /var/www 
    && chown -R www-data:1000 /var/www     
    && usermod -u 1000 www-data 

ADD ./config/php.ini /usr/local/etc/php/php.ini

WORKDIR /var/www

Source: StackOverflow