Skip to content

Commit 9beed15

Browse files
authored
feat(docker): add Docker support for Laravel app (#39)
Introduce Docker support for the Laravel app. - Add `Dockerfile` - Set default to production without debug Signed-off-by: Valentin Sickert <[email protected]>
1 parent 1cfa3b5 commit 9beed15

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

.docker/apache/vhost.conf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<VirtualHost *:80>
2+
3+
ServerAdmin webmaster@localhost
4+
DocumentRoot /var/www/html/public/
5+
6+
<Directory /var/www/>
7+
AllowOverride All
8+
Require all granted
9+
</Directory>
10+
11+
ErrorLog ${APACHE_LOG_DIR}/error.log
12+
CustomLog ${APACHE_LOG_DIR}/access.log combined
13+
14+
</VirtualHost>

.docker/entrypoint.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
set -e; # Exit immediately if a command exits with a non-zero status.
3+
4+
if [ "$APP_ENV" = "production" ]; then
5+
/usr/local/bin/php /var/www/html/artisan migrate --force;
6+
else
7+
/usr/local/bin/php /var/www/html/artisan migrate;
8+
fi
9+
10+
/usr/local/bin/php /var/www/html/artisan optimize;
11+
12+
exec apache2-foreground;

.docker/php/conf.d/opcache.ini

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[opcache]
2+
opcache.enable=1
3+
opcache.revalidate_freq=0
4+
opcache.validate_timestamps=0
5+
opcache.max_accelerated_files=10000
6+
opcache.memory_consumption=192
7+
opcache.max_wasted_percentage=10
8+
opcache.interned_strings_buffer=16
9+
opcache.jit_buffer_size=100M

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.git
2+
.env
3+
.idea
4+
.vscode
5+
node_modules
6+
vendor
7+
storage/framework/cache/**
8+
storage/framework/sessions/**
9+
storage/framework/testing/**
10+
storage/framework/views/**
11+
storage/logs/**

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,6 @@ indent_size = 2
1616

1717
[docker-compose.yml]
1818
indent_size = 4
19+
20+
[*.sh]
21+
end_of_line = lf

Dockerfile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Stage 1: Build
2+
FROM composer:lts as build
3+
4+
WORKDIR /app
5+
6+
COPY . /app/
7+
8+
# Install dependencies
9+
RUN composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction --no-progress
10+
11+
# Stage 2: Production
12+
FROM php:8.1-apache as production
13+
14+
ENV APP_ENV=production
15+
ENV APP_DEBUG=false
16+
17+
# Install Postgres driver
18+
RUN apt-get update && \
19+
apt-get install -y libpq-dev
20+
21+
# Install PHP extensions
22+
RUN docker-php-ext-configure opcache --enable-opcache && \
23+
docker-php-ext-install pdo pdo_mysql pdo_pgsql
24+
25+
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
26+
27+
# Copy opcache config
28+
COPY .docker/php/conf.d/opcache.ini /usr/local/etc/php/conf.d/opcache.ini
29+
30+
# Copy application
31+
COPY --from=build /app /var/www/html
32+
33+
# Copy apache config
34+
COPY .docker/apache/vhost.conf /etc/apache2/sites-available/000-default.conf
35+
36+
# Copy entrypoint
37+
COPY .docker/entrypoint.sh /entrypoint.sh
38+
39+
# Copy configure script
40+
RUN chown -R www-data:www-data /var/www/ && \
41+
a2enmod rewrite
42+
43+
EXPOSE 80
44+
45+
# Run Entrypoint
46+
ENTRYPOINT [ "/entrypoint.sh" ]

0 commit comments

Comments
 (0)