Skip to content

Instantly share code, notes, and snippets.

@JanMikes
Created September 15, 2018 16:59
Show Gist options
  • Save JanMikes/06b2af2a6eacc2c4672c163672604117 to your computer and use it in GitHub Desktop.
Save JanMikes/06b2af2a6eacc2c4672c163672604117 to your computer and use it in GitHub Desktop.
Multi-stage dockerfile with xdebug for local development
version: "3.4"
services:
web:
build:
context: .
target: dev
image: fermakleri:latest
ports:
- 80:80
volumes:
- .:/srv/app:cached
environment:
APP_ENV: "dev"
XDEBUG_CONFIG: "remote_host=host.docker.internal"
PHP_IDE_CONFIG: "serverName=myapp"
depends_on:
- mysql
- mailhog
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_DATABASE: "myapp"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
- ./.docker/mysql-data:/var/lib/mysql
ports:
- 3306:3306
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
####
## Production build
####
FROM php:7.1-apache as production
MAINTAINER Jan Mikeš [email protected]
## Install composer globally
RUN curl -sS https://getcomposer.org/installer | php \
&& mv composer.phar /usr/local/bin/composer
## Enable apache modules
RUN a2enmod headers && a2enmod rewrite
## Install php extensions + cleanup
RUN apt-get update && apt-get install -y \
git \
unzip \
g++ \
zlib1g-dev \
libicu-dev \
libzip-dev \
libpng-dev \
libjpeg-dev \
&& docker-php-ext-configure gd --with-png-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd \
&& docker-php-ext-configure intl \
&& docker-php-ext-install intl \
&& docker-php-ext-install pdo_mysql \
&& pecl install \
zip \
&& docker-php-ext-enable zip \
&& apt-get clean \
&& rm -rf /tmp/* /usr/local/lib/php/doc/* /var/cache/apt/*
## Copy project code
COPY . /application
WORKDIR /application
## Virtual host for apache
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
## Self explaining composer install
RUN composer install
## Setup apache
RUN chown -R www-data:www-data /application
####
## Build for local development
####
FROM production as dev
## Xdebug config
COPY xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini
## Install Xdebug extension + cleanup
RUN pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& apt-get clean \
&& rm -rf /tmp/* /usr/local/lib/php/doc/* /var/cache/apt/*
<VirtualHost *:80>
DocumentRoot /application/web
<Directory "/application/web">
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=0
xdebug.profiler_enable=0
xdebug.remote_port=9001
@vuon9
Copy link

vuon9 commented Nov 8, 2023

This is a nice setup. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment