Reputation: 129
I am trying to get xdebug to work in a php container within a docker-compose setup. I found a few examples that show the extra config lines that need to be added to the container:
From Reddit, I have tried to add these lines in my web container's Dockerfile:
# Configure xdebug
RUN echo "xdebug.remote_enable=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.idekey=PHPSTORM" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_connect_back=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_host=10.10.1.2" >> /etc/php5/fpm/conf.d/20-xdebug.ini
But I am not directly using a dockerfile as far as I can tell.
my docker-compose.yml:
web:
image: tutorial/nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www
- ./src/vhost.conf:/etc/nginx/sites-enabled/vhost.conf
links:
- php
php:
image: nmcteam/php56
volumes:
- ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf
- ./src:/var/www
run:
# Configure xdebug
RUN echo "xdebug.remote_enable=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.idekey=PHPSTORM" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_connect_back=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_host=10.10.1.2" >> /etc/php5/fpm/conf.d/20-xdebug.ini
links:
- db
db:
image: sameersbn/mysql
volumes:
- /var/lib/mysql
environment:
- DB_NAME=demoDb
- DB_USER=demoUser
- DB_PASS=demoPass
Clearly the run: section does not work. I'm missing something, but so far have not been able to get my head around how to solve the problem using compose.
Upvotes: 2
Views: 6782
Reputation: 61551
run
is not a command in docker-compose
you can specify either image
or build
with alternative path to a Dockerfile
So you can use RUN
in your Dockerfile
. Reference
My recommendation is that if you need to run the commands you specified, you can do something like this for your 'php' Dockerfile
:
FROM nmcteam/php56
RUN echo "xdebug.remote_enable=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.idekey=PHPSTORM" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_connect_back=1" >> /etc/php5/fpm/conf.d/20-xdebug.ini
RUN echo "xdebug.remote_host=10.10.1.2" >> /etc/php5/fpm/conf.d/20-xdebug.ini
Build the image:
docker build -t myuser/php56 <path to Dockerfle>
Then in your docker-compose.yml
file, in the 'php' section:
php:
image: myuser/php56
volumes:
- ./src/php-fpm.conf:/etc/php5/fpm/php-fpm.conf
- ./src:/var/www
links:
- db
You can optionally push your image to your dockerhub account:
docker push myuser/php56
Upvotes: 4