This is just a quick post sharing my basic docker setup for new laravel projects.
Setting up a new laravel project can be quite some hassle, the current options with valet, homestead or vagrant are fine but personally don't give me the flexibility I need.
That's why I created a basic laravel docker boilerplate I copy across my projects.
How to use it
First of all you need docker installed on your pc and a laravel projects. Then copy the next two files into the root of your project:
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" |
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; | |
} | |
} |
Once you copied the files, you'll need to run docker-compose up
in the root of your project directory to start the dev environment. Head over to http://localhost and you'll have your laravel project up and running.
--
The following file is optional and meant for if you want to use your own docker container image. The docker-compose above uses my pre-build docker image which is hosted on docker hub.
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 |
If you want to know more about docker or how to setup your own stack, let me know down below and I'll write something about that.
Thanks
Top comments (0)