version: "3.2"
services:
  php:
    build: './docker/php/'
    depends_on:
      - mailcatcher
    networks:
      - backend
    volumes:
      - .:/var/www/html/
    environment:
        DBHOST: 'mysql'
        DBNAME: ${DBNAME}
        DBPASS: ${DBPASS}
        DBUSER: ${DBUSER}
        DB_BACKEND: ${DB_BACKEND}
        API_SERVER: "http://apache"
        DOCKER: 1
  composer:
    restart: 'no'
    image: "composer"
    command: install
    volumes:
      - .:/app
  apache:
    build: './docker/apache/'
    depends_on:
      - php
      - mysql
      - mailcatcher
    networks:
      - frontend
      - backend
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html/
  mysql:
    image: mysql:5.6.40
    networks:
      - backend
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: ${DBNAME}
      MYSQL_PASSWORD: ${DBPASS}
      MYSQL_USER: ${DBUSER}
    ports:
      - "3306:3306"
    volumes:
      - mysql:/var/lib/mysql
  mailcatcher:
    image: schickling/mailcatcher
    networks:
      - frontend
      - backend
    ports: 
      - "1025:1025"
      - "1080:1080"
networks:
  frontend:
  backend:
volumes:
  mysql:

version: "3.2"
services:
  php:
    build: './docker/php/'
    depends_on:
      - mailcatcher
      - mysql
    networks:
      - backend
    volumes:
      - .:/var/www/html/
    environment:
        DBHOST: 'mysql'
        DBNAME: ${DBNAME}
        DBPASS: ${DBPASS}
        DBUSER: ${DBUSER}
        DB_BACKEND: ${DB_BACKEND}
        API_SERVER: "http://apache"
        DOCKER: 1
  composer:
    restart: 'no'
    image: "composer"
    command: install
    volumes:
      - .:/app
  apache:
    build: './docker/apache/'
    depends_on:
      - php
      - mysql
      - mailcatcher
    networks:
      - frontend
      - backend
    ports:
      - "8080:80"
    volumes:
      - .:/var/www/html/
  mysql:
    image: mysql:5.6.40
    networks:
      - backend
    environment:
      MYSQL_RANDOM_ROOT_PASSWORD: 1
      MYSQL_DATABASE: ${DBNAME}
      MYSQL_PASSWORD: ${DBPASS}
      MYSQL_USER: ${DBUSER}
    ports:
      - "3306:3306"
    volumes:
      - mysql:/var/lib/mysql
  mailcatcher:
    image: schickling/mailcatcher
    networks:
      - frontend
      - backend
    ports:
      - "1025:1025"
      - "1080:1080"
networks:
  frontend:
  backend:
volumes:
  mysql:

Make sure db is running when running php
Make sure db is running when running php
