Skip to content

Instantly share code, notes, and snippets.

@fabarea
Created November 28, 2019 09:14
Show Gist options
  • Save fabarea/8ccc2f079b57dbf465f30583638f91e6 to your computer and use it in GitHub Desktop.
Save fabarea/8ccc2f079b57dbf465f30583638f91e6 to your computer and use it in GitHub Desktop.
Docker example PHP

Build

Build + remove old image

docker build --rm -t fab/php72 .

Usage

# Launch php server
docker run -d -p 8000:80 -v "$PWD":/app --name my_project fab/php72
docker exec -ti my_project bash

# Project configuration
# MySQL host configuration "host.docker.internal"

docker stop my_project
docker rm my_project
FROM php:7.2
ENV APP_DIR /app
ENV APPLICATION_ENV development
WORKDIR $APP_DIR
VOLUME $APP_DIR
RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php'); \
\$sig = file_get_contents('https://composer.github.io/installer.sig'); \
if (trim(\$sig) === hash_file('SHA384', 'composer-setup.php')) exit(0); \
echo 'ERROR: Invalid installer signature' . PHP_EOL; \
unlink('composer-setup.php'); \
exit(1);" \
&& php composer-setup.php -- --filename=composer --install-dir=/usr/local/bin \
&& rm composer-setup.php
RUN apt update && apt install -y \
bash
# Minimal bash configuration
RUN /bin/echo -e "alias l=\"ls -la\"" >> /root/.bashrc && \
/bin/echo -e "alias ..=\"cd ../\"" >> /root/.bashrc
# Install PHP extension
RUN docker-php-ext-install mysqli
&& docker-php-ext-enable mysqli
&& docker-php-ext-install zip
&& pecl install xdebug && docker-php-ext-enable xdebug
# Install GD
RUN apt update && apt install -y \
libfreetype6-dev \
libjpeg62-turbo-dev \
libpng-dev \
&& docker-php-ext-configure gd \
--with-freetype-dir=/usr/include/freetype2 \
--with-png-dir=/usr/include \
--with-jpeg-dir=/usr/include
EXPOSE 80
CMD ["php", "-S", "0.0.0.0:80", "-t", "/app/public"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment