Docker + Xdebug + VSCode Could not connect to client - php

PHP version: 7.1.20
XDebug version: 2.7.0
I'm using a Docker container on MacOS Mojave.
On pressing "F5", it shows debug options Pause, Restart, and Stop. But Step Over, Step Into, Step Out are disabled.
I'm kind of learner because I was used to code till 2012-13 on Windows OS. After that year, I am back to coding this month. :) Even after reviewing a lot of posts on Google about how to resolve this issue, I'm not sure how to finally make it work. Please help.
My launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9001,
"log": true,
"pathMappings": {
"/var/www/html": "${workspaceFolder}/learn"
}
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9001
}
]
}
XDebug php.ini config:
xdebug.remote_host = 172.20.0.1
xdebug.remote_port = 9001
xdebug.scream = 1
xdebug.remote_enable = 1
xdebug.show_local_vars = 1
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 1
xdebug.remote_log = "/var/www/html/xdebug.log"
xdebug.idekey = "VSCODE"
XDebug logfile (from setting xdebug.remote_log in php.ini):
[12] Log opened at 2019-05-12 10:16:44
[12] I: Checking remote connect back address.
[12] I: Checking header 'HTTP_X_FORWARDED_FOR'.
[12] I: Checking header 'REMOTE_ADDR'.
[12] I: Remote address found, connecting to 172.20.0.1:9001.
[12] W: Creating socket for '172.20.0.1:9001', poll success, but error: Operation now in progress (29).
[12] E: Could not connect to client. :-(
[12] Log closed at 2019-05-12 10:16:44
Debug console:
<- launchResponse
Response {
seq: 0,
type: 'response',
request_seq: 2,
command: 'launch',
success: true }
Here's the dockerfile.
FROM php:7.1.20-apache
RUN apt-get -y update --fix-missing
RUN apt-get upgrade -y
# Install tools & libraries
RUN apt-get -y install apt-utils nano wget dialog \
build-essential git curl libcurl3 libcurl3-dev zip
# Install important libraries
RUN apt-get -y install --fix-missing apt-utils build-essential git curl libcurl3 libcurl3-dev zip \
libmcrypt-dev libsqlite3-dev libsqlite3-0 mysql-client zlib1g-dev \
libicu-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev
# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# PHP Extensions
RUN pecl install xdebug-2.7.0 \
&& docker-php-ext-enable xdebug \
&& docker-php-ext-install mcrypt \
&& docker-php-ext-install pdo_mysql \
&& docker-php-ext-install pdo_sqlite \
&& docker-php-ext-install mysqli \
&& docker-php-ext-install curl \
&& docker-php-ext-install tokenizer \
&& docker-php-ext-install json \
&& docker-php-ext-install zip \
&& docker-php-ext-install -j$(nproc) intl \
&& docker-php-ext-install mbstring \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install -j$(nproc) gd \
&& pecl install redis \
&& docker-php-ext-enable redis
# Enable apache modules
RUN a2enmod rewrite headers
ENTRYPOINT ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Here's the docker-compose.yml file.
version: "3"
services:
webserver:
build:
context: ./bin/webserver
container_name: '7.1.x-webserver'
restart: 'always'
ports:
- "80:80"
- "443:443"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
mysql:
build: ./bin/mysql
container_name: '5.7-mysql'
restart: 'always'
ports:
- "3306:3306"
volumes:
- ${MYSQL_DATA_DIR-./data/mysql}:/var/lib/mysql
- ${MYSQL_LOG_DIR-./logs/mysql}:/var/log/mysql
environment:
MYSQL_ROOT_PASSWORD: tiger
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: 'sc-phpmyadmin'
links:
- mysql
environment:
PMA_HOST: mysql
PMA_PORT: 3306
ports:
- '8080:80'
volumes:
- /sessions
redis:
container_name: 'sc-redis'
image: redis:latest
ports:
- "6379:6379"
Thank you in advance.

You can have your docker container connect to your host by configuring PHP appropriately.
Note that I've used Docker's host.docker.internal domain, that always points to the host IP.
xdebug.remote_enable=1
xdebug.remote_port=9000
xdebug.idekey=docker
xdebug.profiler_enable=0
xdebug.profiler_enable_trigger=1
xdebug.remote_host=host.docker.internal
There's no need to open ports to the docker container.
Just make sure that your debugging application can listen on the appointed port (9000 in my case) and that this port is not occupied.
Take for example this PhpStorm configuration:
Troubleshooting
Validate that xdebug is installed, run in the php container:
php -i | grep xdebug
Make sure that you're editing the appropriate .ini files, check:
php -i | grep \.ini
If you have idekey enabled, make sure to configure them in your IDE too:
There's a Debugger Config Validator in PhpStorm if you're exposing PHP scripts on a webserver:

Try to open port 9001 in the docker-compose.yml by inserting:
ports:
- "9001:9001"
Example
services:
webserver:
build:
context: ./bin/webserver
container_name: '7.1.x-webserver'
restart: 'always'
ports:
- "80:80"
- "443:443"
- "9001:9001"
links:
- mysql
volumes:
- ${DOCUMENT_ROOT-./www}:/var/www/html
- ${PHP_INI-./config/php/php.ini}:/usr/local/etc/php/php.ini
- ${VHOSTS_DIR-./config/vhosts}:/etc/apache2/sites-enabled
- ${LOG_DIR-./logs/apache2}:/var/log/apache2
See more about configuring docker-compose.yml: https://docs.docker.com/compose/compose-file/
You might be able to use expose. We have that in some of our old Dockerfiles which is intended to allow xDebug connections, but I haven't used it personally.
expose:
- "9001"

You should open port 9001 in your host machine, not in Docker.
Also try to check if Xdebug is configured properly: add phpinfo() to your code and open that page in browser. You shold see xdebug enabled
If Xdebug enabled, maybe your IDE settings are incorrect

For VSCode as the OP has asked and xdebug 3.x.x, the configuration should be -
xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.start_upon_error=yes
xdebug.client_host=[IP address] <<<< NOTE
xdebug.discover_client_host=true
xdebug.client_port=9000
Note: xdebug.client_host should have the host IP address for vscode (192.168...) and not host.docker.internal which does not seem to work for vscode.
Note 2: There is no need to open any port (9000 in the config above) for this purpose. This could be because docker connects back to host at port 9000 and not vice versa!

Related

PHP / How to use remote debugger on remote Docker container

I'm working on a project were files stored on a remote server and this project is running on Docker.
I'm trying to enable Xdebug in PhpStorm but I can't made this working. The first problem is I can't reach the PHP executable inside my remote PHP Docker container.
For clarify : my PhpStorm IDE is on my locale machine, and my docker project is on a remote server.
Inside my remote container docker php path:
And when I'm trying to validate, it doesn't work properly:
; XDEBUG Extension
[xdebug]
xdebug.remote_enable = 1
xdebug.profiler_enable = 0
xdebug.remote_autostart = 1
xdebug.remote_connect_back = 0
xdebug.profiler_enable_trigger = 0
xdebug.show_local_vars = 0
xdebug.remote_port = 9003
xdebug.remote_host = host.docker.internal
xdebug.idekey = PHPSTORM
;xdebug.remote_log = "/var/www/web/var/log/xdebug.log"
xdebug.cli_color = 1
xdebug.extended_info = 1
Is there anyway to have Xdebug working in this configuration ?
Dockercompose
version: '3.0'
services:
apache:
container_name: colis_apache
build:
context: apache
args:
USER_UID: 1000
volumes:
- "../..:/var/www/colis:rw,cached"
- "./logs:/var/log/apache2/:rw"
depends_on:
- db
ports:
- "80:80"
- "443:443"
hostname: "colis.qangles.lan"
networks:
- colis-net
extra_hosts:
- "host.docker.internal:host-gateway"
db:
image: mariadb:10.1.45
container_name: colis_db
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: *****
MYSQL_USER: colis
MYSQL_PASSWORD: ****
volumes:
- "db_colis_data:/var/lib/mysql"
- "../..:/code:rw"
networks:
- colis-net
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: colis_phpmyadmin
links:
- db
environment:
PMA_HOST: db
PMA_USER: root
PMA_PASSWORD: toor
ports:
- "8080:80"
networks:
- colis-net
volumes:
db_colis_data:
networks:
colis-net:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.12.2.0/24
Dockerfile
FROM php:7.3.20-fpm
RUN apt-get update && apt-get install -y \
libicu-dev \
zip \
curl \
libcurl4-openssl-dev \
libmcrypt-dev \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
zlib1g-dev \
libxml2-dev \
libxslt-dev \
libicu-dev \
wget \
curl \
zip \
git \
jpegoptim optipng \
cron
# opcache
RUN docker-php-ext-enable opcache
# Xdebug
RUN pecl install xdebug-3 apcu
RUN docker-php-ext-enable xdebug apcu
# PHP extensions
RUN docker-php-ext-install intl pdo_mysql mysqli calendar soap \
&& docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
exif \
gettext \
bcmath \
shmop \
sockets \
sysvmsg \
sysvsem \
sysvshm \
xsl
# Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN mkdir -p /var/www/.composer
COPY php.ini /usr/local/etc/php/
COPY xdebug.ini /usr/local/etc/php/conf.d/
COPY openssl.cnf /usr/lib/ssl/
RUN mkdir -p /var/www/colis/var/log
RUN chown -R www-data:www-data /var/www
# Set timezone to UTC (as always)
RUN rm /etc/localtime \
&& ln -s /usr/share/zoneinfo/UTC /etc/localtime \
&& date \
&& printf "date.timezone=Europe/Paris\n" > $PHP_INI_DIR/conf.d/timezone.ini
#COPY files/crontab /etc/cron.d/distriartisan
# Change CMD to have cron running
RUN echo "#!/bin/sh\ncron\nphp-fpm" > /usr/bin/run
RUN chmod u+x /usr/bin/run
CMD ["run"]
# Use www-data with correct UID
ARG USER_UID=1000
RUN usermod -u $USER_UID www-data
# Mailcatcher
#RUN echo "sendmail_path = /usr/sbin/ssmtp -t" > /usr/local/etc/php/conf.d/sendmail.ini \
# && echo "mailhub=mail:25\nUseTLS=NO\nFromLineOverride=YES" > /etc/ssmtp/ssmtp.conf
WORKDIR /var/www/colis
you can use sail example to see better
docker-compose.yml
your Dockerfile should have this section
RUN apt-get install -y php8.1-cli php8.1-dev \
php8.1-pgsql php8.1-sqlite3 php8.1-gd \
php8.1-curl \
php8.1-imap php8.1-mysql php8.1-mbstring \
php8.1-xml php8.1-zip php8.1-bcmath php8.1-soap \
php8.1-intl php8.1-readline \
php8.1-ldap \
php8.1-msgpack php8.1-igbinary php8.1-redis php8.1-swoole \
php8.1-memcached php8.1-pcov php8.1-xdebug \
version: '3'
services:
laravel.test:
build:
context: .
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
XDEBUG: ${SAIL_DEBUG}
image: sail-8.1/app
extra_hosts:
- 'host.docker.internal:host-gateway'
ports:
- '${APP_PORT:-80}:80'
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
environment:
WWWUSER: '${WWWUSER}'
LARAVEL_SAIL: 1
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
PHP_IDE_CONFIG: '${PHP_IDE_CONFIG}'
volumes:
- '.:/var/www/html'
networks:
- sail
then set these variable in .env file :
SAIL_XDEBUG_MODE=develop,debug
php.ini file :
[PHP]
post_max_size = 100M
upload_max_filesize = 100M
variables_order = EGPCS
[XDebug]
zend_extension = xdebug.so
xdebug.mode = debug
xdebug.start_with_request = yes
xdebug.discover_client_host = true
xdebug.idekey = VSC
xdebug.client_host = host.docker.internal
xdebug.client_port = 9003
and then create a server in phpStorm setting. with 0.0.0.0 ip and 9003 port.

Opening Docker container port on localhost in browser returns empty response

I'm trying to run a web project from a Docker container,
when I Dockerize the application on a macBook with an intel chip, everything runs fine and I can make a call to the Docker container. But when I run the same project, with the same setup on my M2 MacBook Air, the browser returns an empty response.
("this page isn't working" --> in Chrome)
This happens even though the containers appear to be running...
(Both containers are green lit up --> in Docker Desktop)
The container makes use of an Nginx service and a php service. The .yml file looks as below:
Docker-compose.yml
version: '3'
services:
#PHP Service
app:
build:
context: .
dockerfile: Dockerfile
image: php:8.0.6-fpm
container_name: Asset-Service
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: Asset-Service
SERVICE_TAGS: dev
working_dir: /var/www
volumes:
- ./:/var/www
- ./php/local.ini:/usr/local/etc/php/conf.d/local.ini
networks:
- app-network
#Nginx Service
webserver:
image: nginx:stable
container_name: Asset-Web-Server
restart: unless-stopped
tty: true
ports:
- "8087:80"
- "4487:443"
volumes:
- ./:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d/
networks:
- app-network
#Docker Networks
networks:
app-network:
driver: bridge
#Volumes
volumes:
dbdata:
driver: local
My Dockerfile is the following, even though I don't think that this file causes the problem:
Dockerfile
FROM php:8.0.6-fpm
# Copy composer.lock and composer.json
COPY composer.lock composer.json /var/www/
# Set working directory
WORKDIR /var/www
# Install dependencies
USER root
RUN apt-get update && apt-get install -y \
mariadb-client-10.3 \
libcurl4-openssl-dev \
pkg-config \
libssl-dev \
libpng-dev \
libzip-dev \
libonig-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
locales \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl \
nano
RUN pecl uninstall mongodb
RUN pecl install mongodb
RUN echo "extension=mongodb.so" >> /usr/local/etc/php/conf.d/mongodb.ini
# Clear cache
## RUN apt-get clean && rm -rf /var/lib/apt/lists/*
# Install extensions
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-freetype=/usr/include/ --with-jpeg=/usr/include/
RUN docker-php-ext-install gd
#RUN docker-php-ext-enable mongodb
# Install composer
## RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -fg 1000 www
RUN id -u 1000 >/dev/null 2>&1 || useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory contents
COPY . /var/www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
The container logs look normal and the ports in the inspect tab show 0.0.0.0:8087 and 0.0.0.0:4487.
Is this a recurring issue with the apple silicon version of Docker,
and is there anything I can do about it?
I have already tried to replicate the issue on an Intel macBook, but got the desired result instead of the empty response.
On my M2 I tried reinstalling Docker and rebuilding the containers but this didn't seem to fix anything...
Nevermind this issue.
This problem occurred when trying to build the containers from the Desktop folder.

Debug PHP with Xdebug in Docker with VSCode on Mac

I am running a Symfony application inside a Docker-Container.
I want to debug the code with VSCode on my mac. With Windows everything works fine.
The debugger is connecting to the container, but does not stop at the breakpoints.
This is my launch.json
{
"version": "0.1.0",
"configurations": [{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9003,
"log": true,
"externalConsole": false,
"pathMappings": {
"/srv/app": "${workspaceFolder}",
"/srv/cssp/src/WorkingBundle": "${workspaceFolder}/src/WorkingBundle"
},
"ignore": [
"**/vendor/**/*.php"
]
},
]
In the php.ini I added
xdebug.mode=debug
xdebug.client_host=host.docker.internal
xdebug.start_with_request=trigger
My Dockerfile
FROM composer:latest AS composer
FROM php:7.2-apache-stretch
COPY --chown=33:33 . /srv/cssp
COPY .docker/vhost.conf /etc/apache2/sites-available/000-default.conf
COPY .docker/php.ini /usr/local/lib/
COPY .docker/php.ini /usr/local/lib/php
COPY .docker/php.ini /usr/local/etc/php
WORKDIR /srv/symfonyApp
ENV COMPOSER_ALLOW_SUPERUSER 1
COPY --from=composer /usr/bin/composer /usr/bin/composer
RUN chown -R www-data:www-data /srv/symfonyApp\
&& apt-get update \
&& apt-get -y install libpng-dev libjpeg-dev unzip\
&& docker-php-ext-install -j$(nproc) mbstring mysqli pdo pdo_mysql shmop zip gd \
&& a2enmod rewrite ssl socache_shmcb \
&& service apache2 restart \
&& composer install \
&& chown -R www-data:www-data /srv/symfonyApp\
&& useradd -rm -d /home/symfonyApp -s /bin/bash -g root -G sudo -u 503 cssp \
&& pecl install xdebug \
&& apt install nano \
&& docker-php-ext-enable xdebug \
&& apt-get install libfontconfig1 libxrender1 libxtst6
And my docker-compose.yml
version: '3.8'
services:
app:
build:
context: .
dockerfile: .docker/Dockerfile
image: symfonyApp-docker
ports:
- 8080:80
links:
- mysql
volumes:
- .:/srv/symfonyApp
environment:
PHP_IDE_CONFIG: 'serverName=localhost'
XDEBUG_SESSION: 'VSCODE'
mysql:
image: mariadb:10.4.4
container_name: symfonyApp_mysql
volumes:
- .docker/mysql/init:/docker-entrypoint-initdb.d
restart: always
ports:
- 13306:3306
environment:
MYSQL_ROOT_PASSWORD: secret

Mysql extension not loaded

I got the problem with my Docker Compose. I set up a local development for a old project which using symfony 1.4, PHP 5.5 and Mysql 5.7.30
Everything goes fine until I run the app in browser. Nothing show up and I check the log file. It said:
[error] 6#6: *5 FastCGI sent in stderr: "PHP message: [wrapped: mysql extension not loaded [User Info: Array]]" while reading upstream, client: 118.70.126.249, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.22.0.3:9000"
I also enabled the extension in the php.ini file, but it didn't work.
;extension=php_mysql.dll
;extension=php_mysqli.dll
;extension=pdo_mysql
;extension=php_pdo_mysql.dll
;extension=pdo_mysql.so
This is my screenshot for checking phpinfo()
This is my docker-compose.yml
version: '3'
services:
nginx:
image: nginx:1.11.4
container_name: nginx
ports:
- 8091:80
volumes:
- ./app:/var/www/html
- ./nginx/conf.d/:/etc/nginx/conf.d/
- ./nginx/log/:/var/log/nginx/
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: Dockerfile
container_name: php
ports:
- 9000:9000
working_dir: /var/www/html
volumes:
- ./app:/var/www/html
- ./php/php.ini:/usr/local/etc/php/php.ini
depends_on:
- mysql
mysql:
image: mysql:5.7.30
container_name: mysql
ports:
- 3307:3306
environment:
- MYSQL_ROOT_PASSWORD=secret
- MYSQL_USER=admin
- MYSQL_DATABASE=symfony_db
- MYSQL_PASSWORD=secret
And this is Dockerfile
FROM php:5.5-fpm
WORKDIR /var/www/html
RUN apt-get update && apt-get install -y \
libpng-dev \
libjpeg62-turbo-dev \
libfreetype6-dev \
zip \
jpegoptim optipng pngquant gifsicle \
vim \
unzip \
git \
curl
RUN docker-php-ext-install pdo_mysql mbstring zip exif pcntl
RUN docker-php-ext-configure gd --with-gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ --with-png-dir=/usr/include/
RUN docker-php-ext-install gd
# Install composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Add user for laravel application
RUN groupadd -g 1000 www
RUN useradd -u 1000 -ms /bin/bash -g www www
# Copy existing application directory permissions
COPY --chown=www:www . /var/www
# Change current user to www
USER www
EXPOSE 9000
CMD ["php-fpm"]
Any help are appreciated! Thank you guys!

Docker - Ubuntu - Nginx - MariaDB - Connection refused

Im trying to setup a docker container on OSX with Docker - Ubuntu - Nginx - MariaDB to run a Laravel App
My docker settings are:
version: "2"
services:
nginx:
build:
context: ./nginx
ports:
- "8080:80"
volumes:
- ./app:/var/app
fpm:
build:
context: ./fpm
volumes:
- ./app:/var/app
expose:
- "9000"
environment:
- "DB_HOST=db"
- "DB_DATABASE=laravel_db"
db:
image: mariadb
ports:
- "33061:3306"
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=laravel_db
volumes:
- ./database:/var/lib/mysql
And the 2 docker files:
FROM nginx
ADD ./default.conf /etc/nginx/conf.d/
RUN echo "daemon off;" >> /etc/nginx/nginx.conf
CMD service nginx start
FROM ubuntu:latest
RUN apt-get update && apt-get install -y software-properties-common language-pack-en-base \
&& LC_ALL=en_US.UTF-8 add-apt-repository -y ppa:ondrej/php \
&& apt-get update \
&& apt-get install -y php7.0 php7.0-fpm php7.0-mysql mcrypt php7.0-gd curl \
php7.0-curl php-redis php7.0-mbstring sendmail supervisor \
&& mkdir /run/php \
&& apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
RUN sed -i -e 's/listen = \/run\/php\/php7.0-fpm.sock/listen = 0.0.0.0:9000/g' /etc/php/7.0/fpm/pool.d/www.conf \
&& sed -i -e 's/;daemonize = yes/daemonize = no/g' /etc/php/7.0/fpm/php-fpm.conf
WORKDIR /var/app
EXPOSE 9000
CMD ["/usr/bin/supervisord"]
So far so good. I can access the Laravel App homepage as localhost:8080 and use Sequel Pro to access the MySQL DB.
But when access to the Laravel route that requires DB query, it returns "Connection refused"
Then I create a raw PHP file to make a DB connection test:
$link = mysqli_connect('127.0.0.1', 'root', 'root', 'laravel_db', 33061);
if(!$link) {
die('failed to connect to the server: ' . mysqli_connect_error());
}
And I get connection refused error as well.
I tried using 127.0.0.1 and localhost but no hope.
Tried to google it but most answers are about ports are not published...
Thanks
You need to use the link directive to connect various docker containers when using docker-compose. Ie, if you want to have docker container A communicate with docker container B, they need to be 'linked'
docker-compose documentation on links

Categories