-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Podman php:cli with xdebug: Unable to debug php:cli in Visual Studio Code when using podman (Works in Docker) #1507
Comments
I notice the absence of a port when creating the container. I believe that xdebug2 uses port 9000 while xdebug3 uses 9003 so you might need to export that port for the debugger to connect. |
When I add Is there another way to open a port but not use the port? |
It shouldn't be necessary to set |
For me it is on Manjaro using the latest version of podman |
Strange - it looks like this was added way back in podman 3.2 (https://github.com/containers/podman/releases/tag/v3.2.0)
I have used it for xdebug many times without setting --network=host - Maybe the manjaro package is doing something to disable this feature? It should be easy to test, just check /etc/hosts in any container (containers/podman#10878 (comment)):
Running podman 4.9.4 on fedora |
This is what I get when I run these commands in the terminal...
I wish I can try this on Debian :( but the latest version of Podman available for Debian based distros is 3.4.4 I did try to reproduce this on Fedora inside a VirtualBox VM, but I keep getting an SELinux popup when I run the container and the PHP script in the container which maybe preventing me from using the debugger. I never used Fedora before. |
UPDATE: I disabled SELinux in the Fedora VM by changing |
UPDATE: When I create the container without using the Why is this the case? |
What is the default network mode podman is using? If you omit the --network option entirely when you create your container and then run:
What is the output? |
|
I'm on Fedora 40, podman 5.1.0 my container's NetworkMode is "bridge". I did add the following to
I have a multi-pod setup php-fpm,mysql,nginx etc. From a container I can connect to ports that were exposed and mapped to the host. So for example, I can do curl http://external-ip:8080 or http://nginx:8080 but I can't access anything that is only listening on the host. I'm really curious @ssnepenthe how you have it working. Also my containers don't have "host.containers.internal" added to the hosts file. Not specifically tied to this product but I'm stuck and this is precisely the issue I'm facing. |
I had asked about network mode because I knew there were still some outstanding issues wrt bridge network/pasta backend for rootless containers. e.g. after the switch to pasta by default in v5: containers/podman#22653 While that specific issue has been closed as fixed, it looks like there are still lingering issues: containers/podman#19213 See also the pasta section here: https://blog.podman.io/2024/03/podman-5-0-breaking-changes-in-detail/ There is also some brief discussion of xdebug in issue 19213 starting here: containers/podman#19213 (comment) It looks like the recommendation for now is to switch your default networking tool back to slirp4netns instead of pasta. As for how I have it working - I assume it just works by default because I am still on F39/podman 4.9.4. I have been meaning to upgrade to F40 for a while now - I will report back here when I (eventually) get around to it. |
@ssnepenthe Thank you for the very detailed response and even looking at some of the potential issues. I can confirm that when I change the network back to slirp4netns I can connect from containers to the host. I can continue with regular work now. So I very much appreciate it. |
I am unable to get the VSCode debugger to work with PHP running in a podman container. I was able to set this up using Docker by following these steps...
Dockerfile php.dockerfile
php.ini
VSCode debugger launch config...
Terminal commands to set this all up and run the script
I believe it is due to some networking setup with Podman which requires additional configuring for the debugger attach itself to the PHP script in the Podman container.
I fiddle around with podman some more and found that changing these two things will make debugging work with podman. However this will force the container to use the host network and therefore the container will not get its own network space.
Not sure if this is a good way to go about it for a PHP development environment or if there is a better way to achieve this. The problem with docker setup in the original post compared to podman is when using those steps for podman, the debugger cannot connect to the IDE (VSCode) since the podman container network is isolated as its own network.
Terminal command to create container
php.ini changes
If anyone else knows of a better way to go about this, please do share how it can be done
The text was updated successfully, but these errors were encountered: