This repository contains a Dockerfile
which builds an image
for serving your Laravel app.
Using the image is straight-forward and easy to use, create a Dockerfile
in your app and copy your files into the
container, do whatever is necessary:
FROM laramatics/container:latest
# (optional) copy your own configurations to the container
COPY /docker/config/php.ini "$PHP_INI_DIR/conf.d/laramatics-container.ini"
# (optional) override default nginx configuration file
COPY /docker/config/your_nginx_cnf.conf /etc/nginx/http.d/default.conf
# (optional) add a supervisor configuration file for your workers
COPY /docker/config/myapp.conf /etc/supervisor.d/myapp.conf
# copy app to the container
COPY ./ /var/www/html
Once your files are added to the container, you will have to build an image from your Dockerfile
:
docker build -t <image_name> .
All done! run your container and enjoy!
Although folder structure is self-explanatory, description is below:
.
├── configs
│ ├── crontab.txt # crontab configuration file.
│ ├── nginx.conf # default nginx configuration file.
│ └── supervisord.conf # php/nginx supervisor configuration file.
├── Dockerfile
├── LICENSE
├── readme.md
├── scripts
│ ├── cleanup.sh # Removes build dependencies for lighter image size.
│ ├── install-packages.sh # OS packages will be installed by this file.
│ ├── install-php.sh # PHP extensions and installation.
│ └── start-container # Container entry-point script.
│ └── start-cron # Running container with cron job role.
└── tests
└── goss.yaml # See "testing" section.
We created the Dockerfile
with image size in mind, so only packages and PHP extensions which are absolutely necessary
are installed.
Service | Version | Argument |
---|---|---|
PHP | 8.1.1 | PHP_VERSION |
nginx | latest | N/A |
supervisor | latest | N/A |
As you can see in the table above, some services have an argument in Dockerfile
for you to modify the installation
version. To do so, you need to clone the repo and build the image yourself:
git clone https://github.com/laramatics/container.git
cd app
# Modify files...
docker build \
--build-arg PHP_VERSION=8.1.1 \
-t <image_name> .
If you want to add more extensions to the PHP installation, you will have to build your own image based on the one
already built or modify the Dockerfile
and scripts/*
to your liking and build your own image from that as
described here.
See Docker PHP Extension Installer for available extensions, however you can also install them from the source.
FROM laramatics/container:latest
# add your extentions here...
RUN docker-php-ext-install -j "$(nproc)" <package_name>
Sometimes you need a specific package for your pipeline; as described in the previous section, you can build your own
image from laramatics/container
or clone this repo and modify files to suit your needs.
git clone https://github.com/laramatics/container.git
cd app
# Modify files...
docker build -t <image_name> .
Tests are written using GOSS, to test your changes after modifying source files and building your own image, run:
GOSS_FILES_PATH=tests dgoss run -it <image_name> /bin/ash -l
Q: How can i change php-fpm port?
A: Sometimes you need to change default php-fpm port which is 9000 in order to serve multiple containers under same pod. to do that modify the port in /usr/local/etc/php-fpm.d/zz-docker.conf
.