Final Projects Files
docker-compose.yaml
version: "3.8"
services:
server:
build:
context: .
dockerfile: dockerfiles/nginx.dockerfile
ports:
- '8000:80'
volumes:
- ./src:/var/www/html
- ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf:ro
depends_on:
- php
- mysql
php:
build:
context: .
dockerfile: dockerfiles/php.dockerfile
volumes:
- ./src:/var/www/html:delegated #Optimization performance to avoid the change in /var/www/html to be instantly reflected in our host machine
mysql:
image: mysql:5.7
env_file:
- ./env/mysql.env
composer:
build:
context: ./dockerfiles
dockerfile: composer.dockerfile
volumes:
- ./src:/var/www/html
artisan:
build:
context: .
dockerfile: dockerfiles/php.dockerfile
volumes:
- ./src:/var/www/html
entrypoint: ["php", "/var/www/html/artisan"] # We want to specify an entry point only for the artisan utility not for the php interpreter.
npm:
image: node:14
working_dir: /var/wwww/html
entrypoint: ["npm"]
volumes:
- ./src:/var/www/html
composer.dockerfile
FROM composer:latest
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
USER laravel
WORKDIR /var/www/html
ENTRYPOINT ["composer", "--ignore-platform-reqs"]
nginx.dockerfile
#The creation of this Dockerfile aim to make sure that we always have a snapshot of our configuration and source code inside of a container.
FROM nginx:stable-alpine
#Copying the configuration file that we have on our localhost to the container.
WORKDIR /etc/nginx/conf.d/
COPY /nginx/nginx.conf .
# The nginx server exepct a default.conf file, so we have to rename it.
RUN mv /etc/nginx/conf.d/nginx.conf default.conf
# Changing our Working directory and copy the source code
WORKDIR /var/www/html/
COPY /src .
php.dockerfile
# Very light official php image to base our custom image from.
# The PHP 8.1 version was necessary to avoid an error in Laravel.
FROM php:8.1.0RC5-fpm-alpine3.14
#Folder where the files of our PHP applicatio should be located
WORKDIR /var/www/html
#Copying a snap shot of our source code inside the PHP container (better approach for deployment).
COPY /src .
# To install the php extension we need.
RUN docker-php-ext-install pdo pdo_mysql
# If we do not specify any CMD or ENTRYPOINT instruction, the CMD of the base image will be executed when
# running the container. In the base PHP Docker image, the default command is calling the PHP interpreter.
RUN addgroup -g 1000 laravel && adduser -G laravel -g laravel -s /bin/sh -D laravel
#Granting laravel access to the /var/www/html directory
RUN chown -R laravel:laravel /var/www/html
USER laravel
Last updated