docker-magento icon indicating copy to clipboard operation
docker-magento copied to clipboard

can't enable xdebug, phpfpm container is recreated on restart.

Open MaskeZen opened this issue 2 years ago • 24 comments
trafficstars

Description

When I try to enable the xdebug with bin/xdebug enable and the phpfpm service is restarted the container is recreated, and the value back to the original state.

  • OS: ubuntu.
  • Docker version 23.0.1, build a5ee5b1

Steps To Reproduce

  1. bin/xdebug enable

Expected Result

$ bin/xdebug status
Xdebug debug mode is disabled.

Actual Result

$ bin/xdebug status
Xdebug debug mode is disabled.

MaskeZen avatar Feb 24 '23 01:02 MaskeZen

I have same problem also on Ubuntu. The container keeps recreating and the php.ini change is not persisting.

vy-shmal avatar Feb 24 '23 13:02 vy-shmal

@vy-shmal, as a momentary fix to that I change the compose to mount a volume to that php.ini file.

I create the file ./env/php.ini with the content of the original plus xdebug modifications:

memory_limit = 4G
max_execution_time = 1800
zlib.output_compression = On
cgi.fix_pathinfo = 0
date.timezone = UTC

xdebug.mode=debug
xdebug.start_with_request=yes
xdebug.client_host=host.docker.internal
xdebug.client_port=9003
xdebug.idekey=VSCODE

upload_max_filesize = 100M
post_max_size = 100M
max_input_vars = 10000

sendmail_path = "/usr/bin/msmtp -t"

And then in the compose.yaml file I add a volume...

services:
  app:
    build: images/nginx
    ports:
      - "80:8000"
      - "443:8443"
    volumes: &appvolumes
       - ~/.composer:/var/www/.composer:cached
       - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
       - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
+      - "./env/php.ini:/usr/local/etc/php/php.ini"
       - appdata:/var/www/html
       - sockdata:/sock
       - ssldata:/etc/nginx/certs
-    #extra_hosts: &appextrahosts
+    extra_hosts: &appextrahosts
       ## Selenium support, replace "magento.test" with URL of your site
       #- "magento.test:172.17.0.1"
+      - "host.docker.internal:host-gateway"
 
   phpfpm:
     image: markoshust/magento-php:8.1-fpm-1
     volumes: *appvolumes
     env_file: env/phpfpm.env
-    #extra_hosts: *appextrahosts
+    extra_hosts: *appextrahosts
 
   db:
     image: mariadb:10.4

...

MaskeZen avatar Feb 24 '23 14:02 MaskeZen

@MaskeZen Yes it worked for me also, nice thank you.

vy-shmal avatar Feb 24 '23 14:02 vy-shmal

@MaskeZen Thanks. I have the same issue and this works with a small change like below. maybe help someone

- ~/.env/php.ini:/usr/local/etc/php/php.ini

markosege avatar Feb 28 '23 18:02 markosege

I've been experiencing the same issue on Ubuntu 22.04.2 and, after some research, I've found that the issue seems to reside in the docker compose command being called in bin/docker-compose when running bin/start.

To fix the issue I've just updated the bin/docker-compose file as follows:

#!/bin/bash

if docker compose version > /dev/null 2>&1; then
-  DOCKER_COMPOSE="docker compose"
+  DOCKER_COMPOSE="docker-compose"
else
  DOCKER_COMPOSE="docker-compose"
fi

if [ "$1" == "--no-dev" ]; then
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml "${@:2}"
else
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml -f compose.dev.yaml "$@"
fi

I'm not sure why the docker compose is behaving differently than docker-compose, but might as well be a @docker internal issue.

xavierojeda avatar Mar 01 '23 16:03 xavierojeda

Confirm same behavior on manjaro linux with Docker Compose version 2.16.0

phpfpm container is recreated and xdebug is never enabled.

If I downgrade to Docker Compose version 2.14.2 then xdebug gets enabled as expected.

btantlinger avatar Mar 01 '23 18:03 btantlinger

@MaskeZen Thanks. I have the same issue and this works with a small change like below. maybe help someone

- ~/.env/php.ini:/usr/local/etc/php/php.ini

This depend on where you want to put your php.ini file.

MaskeZen avatar Mar 01 '23 19:03 MaskeZen

@rangerz is it possible that bin/docker-compose script is returning a false positive on the first conditional check?

if docker compose version > /dev/null 2>&1; then
  DOCKER_COMPOSE="docker compose"
else
  DOCKER_COMPOSE="docker-compose"
fi

markshust avatar Mar 03 '23 14:03 markshust

Hello @markshust , no, this is ok, almost in my case.

bash test

MaskeZen avatar Mar 03 '23 15:03 MaskeZen

@xavierojeda what is your output of the above?

markshust avatar Mar 03 '23 16:03 markshust

@xavierojeda what is your output of the above?

Hi @markshust. My output is the same as @MaskeZen's. Screenshot from 2023-03-03 17-46-06

xavierojeda avatar Mar 03 '23 17:03 xavierojeda

@xavierojeda try docker compose version to check that you have docker compose installed.

MaskeZen avatar Mar 03 '23 17:03 MaskeZen

@xavierojeda try docker compose version to check that you have docker compose installed.

Forgot to attach the output for that one. Here it is: Screenshot from 2023-03-03 17-53-38

xavierojeda avatar Mar 03 '23 17:03 xavierojeda

I have same problem also on Ubuntu. The container keeps recreating and the php.ini change is not persisting.

Going back to this... why is the container getting recreated? This doesn't make any sense. It should only start/stop, not get completely destroyed and then recreated.

markshust avatar Mar 03 '23 18:03 markshust

@rangerz is it possible that bin/docker-compose script is returning a false positive on the first conditional check?

if docker compose version > /dev/null 2>&1; then
  DOCKER_COMPOSE="docker compose"
else
  DOCKER_COMPOSE="docker-compose"
fi

I can't replicate

rangerz avatar Mar 06 '23 07:03 rangerz

Any update for this issue?

Everytime that I execute bin/xdebug toggle the xdebug is not enabled. @markshust I have the latest version of your package.

This works:

bin/root sed -i -e 's/^xdebug.mode = off/xdebug.mode = debug/g' /usr/local/etc/php/php.ini

but when I try to use bin/restart phpfpm I can see that the restart reset the php.ini to the default values:

xdebug.mode = off

Why this happens?

thanks

shinesoftware avatar Mar 10 '23 07:03 shinesoftware

Yea I really can't see why that would be happening, unless the container is completely destroyed when it shuts down.

I don't think the docker compose thing is any issue at all, as that line should properly return the exact version of docker compose you are running depending on the installed version.

That said, I'm not opposed to creating a new conf/php.ini file in the compose directory, as this would allow someone to easily edit the php.ini file right on the host. And since this file is mounted from the local filesystem, it should absolutely persist container restarts. If someone wants to test this out locally, and if it works, make a PR, I'll take this in.

markshust avatar Mar 16 '23 19:03 markshust

Thanks @MaskeZen , you save my time!

ngtuan96lc avatar Mar 17 '23 05:03 ngtuan96lc

First of all, i made the changes @MaskeZen recommended and after that, still doesnt working.

So after some tests i had to increment some this changes to get all working as expected.

System:

  • Ubuntu 20.04.6
  • PHPSTORM
  • Docker version 23.0.1, build a5ee5b1
  • Docker Compose version v2.17.2

Uncomment these lines in compose.yaml extra_hosts: - "host.docker.internal:host-gateway"

Add this entry on /etc/hosts 172.17.0.1 host.docker.internal

obs: To check the host you can paste this on your terminal docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'

Change server path mapping on phpstorm servers to the "pub" directory, as the screenshot /var/www/html/pub image

Hope it helps someone!

FXXDEV avatar Mar 29 '23 00:03 FXXDEV

I've been experiencing the same issue on Ubuntu 22.04.2 and, after some research, I've found that the issue seems to reside in the docker compose command being called in bin/docker-compose when running bin/start.

To fix the issue I've just updated the bin/docker-compose file as follows:

#!/bin/bash

if docker compose version > /dev/null 2>&1; then
-  DOCKER_COMPOSE="docker compose"
+  DOCKER_COMPOSE="docker-compose"
else
  DOCKER_COMPOSE="docker-compose"
fi

if [ "$1" == "--no-dev" ]; then
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml "${@:2}"
else
  ${DOCKER_COMPOSE} -f compose.yaml -f compose.healthcheck.yaml -f compose.dev.yaml "$@"
fi

I'm not sure why the docker compose is behaving differently than docker-compose, but might as well be a @docker internal issue.

thanks , it's really helps!

killvap avatar Apr 26 '23 09:04 killvap

@killvap I have same issue and try to fix like your way but i am getting this error ERROR: The Compose file './compose.healthcheck.yaml' is invalid because: services.phpfpm.depends_on contains an invalid type, it should be an array services.app.depends_on contains an invalid type, it should be an array ERROR: The Compose file './compose.healthcheck.yaml' is invalid because: services.phpfpm.depends_on contains an invalid type, it should be an array services.app.depends_on contains an invalid type, it should be an array

markosege avatar May 10 '23 15:05 markosege

I also encountered the same problem. If I just start the phpfpm service it works fine docker compose -f compose.yaml -f compose.healthcheck.yaml -f compose.dev.yaml start php-fpm

xdebug-bug

lzyenjoy avatar May 18 '23 05:05 lzyenjoy

Had the same issue on MacOS until I upgraded Docker Desktop to v4.20.1 and Docker Compose to v2.18.1.

mts527 avatar Jun 19 '23 08:06 mts527

Had the same issue on MacOS until I upgraded Docker Desktop to v4.20.1 and Docker Compose to v2.18.1.

I can confirm that upgrading Docker Desktop solved this issue for me as well.

Thank you @mts527 for taking the time to leave this comment.

victortodoran avatar Jan 06 '24 14:01 victortodoran