Answer the question
In order to leave comments, you need to log in
How to make php-fpm in docker-compose connect to local mysql?
Here is my docker-compose.yml file
version: '3'
services:
fpm:
build: /images/php
volumes:
- /var/www:/var/www
- /var/www/php-ini:/usr/local/etc/php/custom.d
environment:
PHP_INI_SCAN_DIR: "/usr/local/etc/php/custom.d:/usr/local/etc/php/conf.d"
ports:
- "127.0.0.1:9074:9000"
FROM php:7.4-fpm
MAINTAINER PHPtoday.ru <[email protected]>
RUN apt-get update && apt-get install -y \
curl \
wget \
git \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
libonig-dev \
libzip-dev \
libmcrypt-dev \
&& pecl install mcrypt-1.0.3 \
&& docker-php-ext-enable mcrypt \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip \
&& docker-php-ext-configure gd --with-freetype --with-jpeg \
&& docker-php-ext-install -j$(nproc) gd
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --
filename=composer
ADD php.ini /usr/local/etc/php/conf.d/40-custom.ini
WORKDIR /var/www
CMD ["php-fpm"]
Answer the question
In order to leave comments, you need to log in
In the MySQL config, as an IP, enter the address of the container's gateway, which one you can look at, docker inspect <container_name>
or look at the output ip a
- this address will also be visible on the container's bridge.
Then, in the connection settings, specify this IP as the MySQL host.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question