Docker lumen app throwing php_network_getaddresses: getaddrinfo failed: Name or service not known

Viewed 1369

I'll start by saying that I am brand new to Docker. I am trying to do a proof of concept for Docker with an existing Lumen microservice but can't seem to get the mysql container on my local to work properly.

When I run php artisan migrate, I get this error:

SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Name or service not known

Here is my docker-compose.yml file

version: '3.7'

services:
  # Nginx
  web:
    image: nginx:latest
    ports:
      - '8080:80'
    volumes:
      - .:/app
      - .docker/nginx/site.conf:/etc/nginx/conf.d/default.conf
    links:
      - php

  # Database
  db:
    container_name: db
    image: mysql:5.7.24
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
    - '3306:3306'
    environment:
      MYSQL_ROOT_PASSWORD: local_mysql_password
      MYSQL_DATABASE: partners

  # PHP
  php:
    build: .
    volumes:
      - .:/app
    links:
      - db
    depends_on:
      - db

And my Dockerfile for the php image

FROM php:7.2-fpm

ADD . /app

WORKDIR /app

RUN apt-get update \
 && apt-get install -y git libpng-dev libxml2-dev libzip-dev zip \
 && docker-php-ext-configure zip --with-libzip \
 && docker-php-ext-install \
    pdo_mysql \
    gd \
    zip \
 && curl -sS https://getcomposer.org/installer \
  | php -- --install-dir=/usr/local/bin --filename=composer

RUN composer install

RUN php artisan migrate

I am using the following in my .env file for the DB connection

DB_CONNECTION=mysql
DB_HOST=db
DB_PORT=3306
DB_DATABASE=partners
DB_USERNAME=root
DB_PASSWORD=local_mysql_password

I have tried tweaking the port, changing the service name, container_name, links/depends_on settings, and a handful of other things I can't recall at the moment. I have tried multiple solutions from here, reddit, and github but none have worked. Is there something basic I am overlooking?

0 Answers
Related