Skip to content

Instantly share code, notes, and snippets.

@texe
Created November 22, 2021 15:46
Show Gist options
  • Save texe/5fe1384f8535b4bb2e0454fa8bb548d6 to your computer and use it in GitHub Desktop.
Save texe/5fe1384f8535b4bb2e0454fa8bb548d6 to your computer and use it in GitHub Desktop.
Nginx and PHP in Docker
# Set master image
FROM php:7.4-fpm-alpine
# Set working directory
WORKDIR /var/www/html
# Install Additional dependencies
RUN apk update && apk add --no-cache \
build-base shadow vim curl \
php7 \
php7-fpm \
php7-common \
php7-pdo \
php7-pdo_mysql \
php7-mysqli \
php7-mcrypt \
php7-mbstring \
php7-xml \
php7-openssl \
php7-json \
php7-phar \
php7-zip \
php7-gd \
php7-dom \
php7-session \
php7-zlib
# Add and Enable PHP-PDO Extenstions
RUN docker-php-ext-install pdo pdo_mysql mysqli
RUN docker-php-ext-enable pdo_mysql
# Install PHP Composer
#RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
# Remove Cache
RUN rm -rf /var/cache/apk/*
# Add UID '1000' to www-data
RUN usermod -u 1000 www-data
# Copy existing application directory permissions
COPY --chown=www-data:www-data . /var/www/html
# Change current user to www
USER www-data
# Expose port 9000 and start php-fpm server
EXPOSE 9000
CMD ["php-fpm"]
version: '3'
services:
#PHP App
app:
build:
context: .
dockerfile: config/dockerfile
image: christexe/php:7.4-fpm-alpine
container_name: php_app
restart: unless-stopped
tty: true
environment:
SERVICE_NAME: app
SERVICE_TAGS: dev
working_dir: /var/www/html
volumes:
- ./code/:/var/www/html
- ./config/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
networks:
- labnet
#Nginx Service
nginx:
image: nginx:alpine
container_name: nginx
restart: unless-stopped
tty: true
ports:
- "80:80"
volumes:
- ./code/:/var/www/html
- ./config/conf.d/:/etc/nginx/conf.d/
networks:
- labnet
#Docker Networks
networks:
labnet:
external:
name: labnet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment