I'm currently trying to link the host's database with php-fpm inside the docker container.
However, I have to ask you a question because the area is not working properly.
I didn't use php offical base image. so, i created a docker file as shown below and built an image.
RUN apt-get update --fix-missing && \
apt-get -qq -y install aptitude software-properties-common
RUN aptitude purge `dpkg -l | grep php| awk '{print $3}' |tr "\n" " "`
RUN add-apt-repository ppa:ondrej/php
RUN apt-get update
# install php7 fpm
RUN apt-get -qq -y install build-essential wget && \
apt-get -qq -y install php-pear \
php7.0-fpm php7.0-cli php7.0-gd php7.0-curl php7.0-mbstring php7.0-xml php7.0-simplexml \
php7.0-iconv php7.0-json php7.0-mcrypt libapache2-mod-php7.0 php7.0-mysql
# clean up
RUN apt-get -qq -y --purge remove git subversion
# remove package
RUN apt-get -qq -y --purge remove build-essential wget && \
apt-get -qq -y autoremove && \
apt-get clean && \
rm -rf /tmp/src
# add config
ADD php.ini /etc/php/7.0/fpm/php.ini
ADD php-fpm.conf /etc/php/7.0/fpm/php-fpm.conf
ADD www.conf /etc/php/7.0/fpm/pool.d/www.conf
# log configure
RUN mkdir -p /var/log/php && \
touch /var/log/php/fpm-php.www.log && \
chown -R www-data:www-data /var/log/php/fpm-php.www.log
RUN ln -sf /dev/stderr /var/log/php/fpm-php.www.log
# RUN
COPY entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/entrypoint.sh && \
ln -s usr/local/bin/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["entrypoint.sh"]
VOLUME /var/run/php
CMD ["/usr/sbin/php-fpm7.0", "-F"]
I originally built an image of the website with php5-fpm instead of php7-fpm, and there was no operational problem with php5-fpm. But, there was a problem when I uploaded it to version 7.
Thinking that this might be a problem for the database, I started checking for possible problems with the database.
- Verify that the bind-address of the host's database is set to 0.0.0.0.0. This part is thought to cause serious security problems, but we set it up because we're in a hurry to operate.
- Created 'user'@'%' remote access enabled.
- Give database permissions to the user.
However, there was an error 'Connection time out'. Then, I set the log level to a maximum of 9 to start checking all logs.
At that time, I saw the log below.
2019-05-07 1:10:34 57 [Warning] Aborted connection 57 to db: 'unconnected' user: 'unauthenticated' host: 'localhost' (CLOSE_CONNECTION)
I did googling and found that you were solving this problem by adding '--skip-name-reslove' from mysql, but i couldn't resolve the problem.
I uploaded my docker-compose source file just in case.
version: '3'
services:
nginx:
build:
context: ./nnet-nginx/
restart: always
image: seansin/nnet-nginx:latest
depends_on:
- app
volumes:
- app:/var/www/html/zbxe:rw
- php:/var/run/php
- log:/var/log/php
network_mode: "bridge"
ports:
- 80:80
app:
build:
context: ./nnet-app-php7/
restart: always
image: seansin/nnet-app-php7:latest
environment:
- XE_DBCONFIG_FILE=${XE_DBCONFIG_FILE}
- DB_USER=${DB_USER}
- DB_PORT=${DB_PORT}
- DB_PASS=${DB_PASS}
- DB_NAME=${DB_NAME}
volumes:
- app:/var/www/html/zbxe:rw
- php:/var/run/php
- log:/var/log/php
volumes:
app:
php:
log:
Also, my development environment is two things.
- Windows 10 / MariaDB 10.3 (host's DB) / Docker-Engine 18.09.1
- MacOS Mojave / MariaDB 10.3 (host's DB) / Docker-Engine 18.09.1
Inside the docker container, you are trying to connect using the address 'host.docker.internal'.
Linux uses the command '/sbin/ip route|awk '/default/ {print $3 }'
The same problem occurs in both development environments. What's the problem?