I am new to docker and am trying to containerize an existing PHP codebase that uses Phinx for migration purposes. When I go to run docker-compose build
it starts to build the php service and throws the following error:
PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Name does
not resolve
I'm assuming it has to do with the order of services or the mysql service in particular not running/setting the hostname for other services during the actual build process since hostname resolution works properly if the hostname lookup is done after the image is built and running.
Here is my docker-compose.yml contents:
version: '3.2'
services:
nginx:
build: './docker/nginx/'
ports:
- '8080:80'
volumes:
- ./:/var/www/html
links:
- mysql
- mysql:app
mysql:
image: mysql:5.7
volumes:
- "mysql_data:/var/lib/mysql"
environment:
- MYSQL_ROOT_PASSWORD=rootpass
- MYSQL_DATABASE=app
- MYSQL_USER=app
- MYSQL_PASSWORD=password
ports:
- '3306:3306'
restart: unless-stopped
redis:
image: redis
ports:
- '6379:6379'
restart: unless-stopped
php:
build:
context: ./
dockerfile: './docker/php/Dockerfile'
volumes:
- ./:/var/www/html/
links:
- mysql
- mysql:app
volumes:
mysql_data:
Here is my PHP Dockerfile:
FROM php:7.2.7-fpm-alpine3.7
RUN apk update; \
apk upgrade;
RUN docker-php-ext-install pdo pdo_mysql
RUN curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/bin/ --filename=composer
WORKDIR /var/www/html
COPY . /var/www/html
#RUN composer install --no-dev --no-interaction -o
RUN vendor/bin/phinx migrate