From 99db609563bd2d3fdf49d15eb6e372771759951f Mon Sep 17 00:00:00 2001 From: Muthukumaran <120544258+muthukumaran-muthiah@users.noreply.github.com> Date: Thu, 23 Jan 2025 11:44:08 +0530 Subject: [PATCH] Dockerization added. Signed-off-by: muthukumaran-muthiah <120544258+muthukumaran-muthiah@users.noreply.github.com> --- Dockerfile | 23 +++++++++++++++++++++++ README.md | 7 +++++++ docker-compose.yml | 19 +++++++++++++++++++ nginx.conf.dist | 29 +++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 nginx.conf.dist diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..5ef94372 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,23 @@ +# Use the official PHP image as the base image +FROM php:8.3-fpm + +# Set working directory +WORKDIR /var/www/html + +# Install system dependencies +RUN apt-get update && apt-get install -y \ + git \ + unzip + +# Install Composer +COPY --from=composer:latest /usr/bin/composer /usr/bin/composer + +# Copy existing application directory contents +COPY . /var/www/html + +# Install PHP dependencies +RUN composer install + +# Expose port 9000 and start php-fpm server +EXPOSE 9000 +CMD ["php-fpm"] diff --git a/README.md b/README.md index 0b0b1a35..41319047 100644 --- a/README.md +++ b/README.md @@ -52,6 +52,13 @@ After choosing and installing the packages you want, go to the $ composer serve ``` +Or use Docker Compose to run the app: + +```bash +$ cp nginx.conf.dist nginx.conf +$ docker compose up -d +``` + You can then browse to http://localhost:8080. ## Installing alternative packages diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..40ba0c3d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,19 @@ +services: + php: + build: + context: . + dockerfile: Dockerfile + volumes: + - .:/var/www/html + expose: + - 9000 + + nginx: + image: nginx:latest + ports: + - "80:80" + volumes: + - .:/var/www/html + - ./nginx.conf:/etc/nginx/nginx.conf + depends_on: + - php diff --git a/nginx.conf.dist b/nginx.conf.dist new file mode 100644 index 00000000..2fb325d1 --- /dev/null +++ b/nginx.conf.dist @@ -0,0 +1,29 @@ +events { + worker_connections 1024; +} + +http { + server { + listen 80; + server_name localhost; + + root /var/www/html; + index public/index.php index.html index.htm; + + location / { + try_files $uri $uri/ /public/index.php?$query_string; + autoindex on; + } + + location ~ \.php$ { + include fastcgi_params; + fastcgi_pass php:9000; + fastcgi_index public/index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + } + + location ~ /\.ht { + deny all; + } + } +}