Setting up Laravel with Docker : Part 1

“Clusters of shipping containers arranged in rows as seen in Barcelona.” by Tim Easley on Unsplash
Docker version 17.09.0-ce, build afdb6d4
+-- laravel
| +-- app
| +-- docker
| | +-- Dockerfile
| | +-- supervisord.conf
| | +-- default
cd ~
mkdir -p laravel/app laravel/docker
touch laravel/docker/Dockerfile

Building docker container

FROM php:7.0-fpm

LABEL maintainer="Subash Adhikari <me@subash.com.au>"

RUN apt-get update \
&& apt-get install -y nginx curl zip unzip git supervisor sqlite3 \
&& php -r "readfile('http://getcomposer.org/installer');" | \
php -- --install-dir=/usr/bin/ --filename=composer \
&& echo "daemon off;" >> /etc/nginx/nginx.conf \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& apt-get -y autoremove && apt-get clean \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/www/html/*

COPY default /etc/nginx/sites-available/default
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf

EXPOSE 80

CMD ["/usr/bin/supervisord"]
FROM php:7.0-fpm
LABEL maintainer="Subash Adhikari <[email protected]>"
apt-get update \
&& apt-get install -y nginx curl zip unzip git supervisor sqlite3 \
&& php -r "readfile('http://getcomposer.org/installer');" | \ 
php -- --install-dir=/usr/bin/ --filename=composer \
&& echo "daemon off;" >> /etc/nginx/nginx.conf \
&& ln -sf /dev/stdout /var/log/nginx/access.log \ 
&& ln -sf /dev/stderr /var/log/nginx/error.log \
&& apt-get -y autoremove && apt-get clean \ 
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /var/www/html/*
COPY default /etc/nginx/sites-available/default 
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
EXPOSE 80
CMD ["/usr/bin/supervisord"]
server {
root /var/www/html/public;

index index.html index.htm index.php;

server_name _;
charset utf-8;

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; }

location / {
try_files $uri $uri/ /index.php$is_args$args;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass 127.0.0.1:9000;
}

error_page 404 /index.php;

location ~ /\.ht {
deny all;
}
}
[supervisord]
nodaemon=true

[program:nginx]
command=nginx
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:php-fpm]
command=php-fpm
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

Building the image

docker build -t subashcom/laravel ~/laravel/docker

Installing laravel

docker run -it --rm \
-w /var/www \
-v ~/laravel/app:/var/www/html \
subashcom/laravel \
composer create-project --prefer-dist laravel/laravel html

Running the application

docker run -d --rm \
--name=laravel
-p 80:80 -p 9000:9000
-w /var/www \
-v ~/laravel/app:/var/www/html \
subashcom/laravel

Conclusion

Related Posts

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store