Connection between two docker containers

0

I created 3 containers to start my application, they are:

version: "2"

services:

mysql:
  image: mysql:5.7
  container_name: rgsistema-mysql
  working_dir: /application
  volumes:
    - .:/application
  environment:
    - MYSQL_ROOT_PASSWORD=rgsistema
    - MYSQL_DATABASE=rgsistema
    - MYSQL_USER=rgsistema
    - MYSQL_PASSWORD=rgsistema
  ports:
    - "3306:3306"

webserver:
  image: nginx:alpine
  container_name: rgsistema-webserver
  working_dir: /application
  volumes:
    - ./rgsistema/:/application
    - ./phpdocker/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
  ports:
    - "8888:80"
  links:
    - mysql

php-fpm:
  build: phpdocker/php-fpm
  container_name: rgsistema-php-fpm
  working_dir: /application
  volumes:
    - ./rgsistema/:/application
    - ./phpdocker/php-fpm/php-ini-overrides.ini:/etc/php/7.2/fpm/conf.d/99-overrides.ini
  links:
    - mysql

My application is running OK, but it can not connect to the database, it displays the following error:

SQLSTATE[HY000] [2002] Connection refused

I'm using Laravel 5, my .env is as follows:

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=rgsistema
DB_USERNAME=rgsistema
DB_PASSWORD=rgsistema

When testing the connection between them, I have the following answer:

docker container exec -it rgsystem-webserver ping rgsystem-php-fpm = ok

docker container exec -it rgsystem-webserver ping rgsystem-mysql = ok

docker container exec -it rgsystem-php-fpm ping rgsystem-mysql = error

docker container exec -it rgsystem-php-fpm ping rgsystem-webserver = error

Error presented:

OCI runtime exec failed: exec failed: container_linux.go:348: starting container process caused "exec: \"ping\": executable file not found in $PATH": unknown

docker ps

    
asked by anonymous 29.12.2018 / 20:19

0 answers