Skip to content

Instantly share code, notes, and snippets.

@lostdesign
Last active January 15, 2024 03:06
Show Gist options
  • Save lostdesign/3c8caabf703ff40b6d3ae336b58e0c8e to your computer and use it in GitHub Desktop.
Save lostdesign/3c8caabf703ff40b6d3ae336b58e0c8e to your computer and use it in GitHub Desktop.
Run your Laravel project using Docker

Quick laravel-docker stack which comes with php 7.4, nginx, mariadb, redis and metabase.

Installation

  1. Install docker
  2. Place all three files into your laravel root directory
  3. Run docker-compose up or docker-compose up -d to run it in the background
  4. Open your laravel project at http://localhost - metabase is at http://localhost:3000

Troubleshooting

  • If the laravel app is not working, connect to the container with docker exec -it lara-php bash and adjust the folder permissions accordingly to laravel docs.

If there are any other issues, contact me on twitter @lostdesign or discord at lost#0001 or https://discord.gg/devcord

version: "3"
services:
nginx:
container_name: lara-nginx
image: nginx
working_dir: /www
ports:
- "80:80"
volumes:
- ./site.conf:/etc/nginx/conf.d/default.conf
- ./:/www:delegated
php:
container_name: lara-php
image: lostdesign/laravel:1.2
working_dir: /www
volumes:
- ./:/www:delegated
mysql:
container_name: lara-mysql
image: mariadb
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: test123
redis:
container_name: lara-redis
image: redis
ports:
- "6382:6379"
metabase:
container_name: lara-metabase
image: metabase/metabase
ports:
- "3000:3000"
FROM php:7.4-fpm
RUN apt-get update && apt-get install -qy --no-install-recommends \
curl \
openssl \
libfreetype6-dev \
libjpeg62-turbo-dev \
libmagickwand-dev \
libmcrypt-dev \
libgmp-dev\
libpng-dev \
zlib1g-dev \
libxml2-dev \
libzip-dev \
libonig-dev \
zip \
unzip
RUN docker-php-ext-install \
bcmath \
ctype \
json \
mbstring \
pdo \
tokenizer \
xml \
pdo_mysql \
gmp \
intl \
pcntl
RUN yes | pecl install \
igbinary \
xdebug \
imagick \
&& echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_enable=on" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_autostart=off" >> /usr/local/etc/php/conf.d/xdebug.ini \
&& echo "xdebug.remote_port=9001" >> /usr/local/etc/php/conf.d/xdebug.ini
RUN docker-php-ext-enable \
imagick
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
server {
index index.php index.html;
root /www/public/;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ /index.php?$query_string;
gzip_static on;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment