Skip to content

Instantly share code, notes, and snippets.

@beisong7
Forked from shov/Dockerfile
Last active April 13, 2021 14:22
Show Gist options
  • Save beisong7/9297379e1b19ea3c33eed85c79bd3ca8 to your computer and use it in GitHub Desktop.
Save beisong7/9297379e1b19ea3c33eed85c79bd3ca8 to your computer and use it in GitHub Desktop.
Docker PHP 7.2 fpm with GD jpg, png suppot
version: '3.5'
services:
mysql-db:
image: mysql:5.7
restart: always
container_name: mysql-db
# volumes:
# - ./run/var:/var/lib/mysql
volumes:
- my-db:/var/lib/mysql
environment:
- MYSQL_DATABASE=${DB_DATABASE}
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
# - MYSQL_ROOT_PASSWORD=superRootPassword
- MYSQL_USER=root
- MYSQL_HOST=localhost
# - MYSQL_PASSWORD=secret
ports:
- '7010:3306'
expose:
- '7010'
# command: --default-authentication-plugin=mysql_native_password
networks:
backend:
aliases:
- db
officenode-app:
build:
context: '.'
args:
uid: ${UID}
container_name: office-node
restart: always
environment:
- APACHE_RUN_USER=#${UID}
- APACHE_RUN_GROUP=#${UID}
volumes:
- .:/var/www/html
# - /var/www/html
ports:
- 80:80
# - 8080:80
networks:
backend:
aliases:
- office-node
networks:
backend:
name: backend-network
volumes:
my-db: {}
FROM php:7.2-apache
RUN apt-get update
# WORKDIR /app
RUN apt-get install -y \
git \
zip \
curl \
sudo \
unzip \
libicu-dev \
libbz2-dev \
libpng-dev \
libjpeg-dev \
libmcrypt-dev \
libreadline-dev \
libfreetype6-dev \
g++
# 2. apache configs + document root
ENV APACHE_DOCUMENT_ROOT=/var/www/html/public
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/conf-available/*.conf
# 3. mod_rewrite for URL rewrite and mod_headers for .htaccess extra headers like Access-Control-Allow-Origin-
RUN a2enmod rewrite headers
# 4. start with base php config, then add extensions
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
RUN docker-php-ext-install \
gd \
bz2 \
exif \
intl \
iconv \
mysqli \
bcmath \
gettext \
opcache \
mbstring \
calendar \
pdo_mysql \
zip
# 4.1 - configure GD for image convertion/image intervention
RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/ \
&& docker-php-ext-install gd
# 5. install composer (approach a)
# COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
# 5.1 install composer (approach b)
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# 6. we need a user with the same UID/GID with host user
# so when we execute CLI commands, all the host file's ownership remains intact
# otherwise command from inside container will create root-owned files and directories
ARG uid
RUN useradd -G www-data,root -u $uid -d /home/devuser devuser
RUN mkdir -p /home/devuser/.composer && \
chown -R devuser:devuser /home/devuser
#RUN chown -R devuser:devuser /var/www/html
#RUN chmod -R 777 /var/www/test/public_html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment