Skip to content

Commit a3de0e3

Browse files
feat: new docker files
1 parent 10ccc89 commit a3de0e3

File tree

4 files changed

+264
-96
lines changed

4 files changed

+264
-96
lines changed

.docker/Dockerfile

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Dockerfile for Laravel using serversideup/php (API-Only)
2+
3+
#
4+
# Builder Stage
5+
#
6+
# This stage installs all the PHP dependencies.
7+
#
8+
FROM serversideup/php:8.4-cli as builder
9+
10+
# Switch to root to install system packages
11+
USER root
12+
13+
# Install build dependencies (removed nodejs and npm)
14+
RUN apt-get update && apt-get install -y \
15+
build-essential \
16+
libpng-dev \
17+
libjpeg62-turbo-dev \
18+
libfreetype6-dev \
19+
locales \
20+
zip \
21+
jpegoptim optipng pngquant gifsicle \
22+
vim \
23+
unzip \
24+
git \
25+
curl
26+
27+
# Set working directory
28+
WORKDIR /var/www/html
29+
30+
# Switch to the non-privileged user for subsequent operations
31+
USER www-data
32+
33+
# Add an exception for the git repository to avoid ownership errors
34+
RUN git config --global --add safe.directory /var/www/html
35+
36+
# --- Dependency Installation ---
37+
# Copy only composer dependency files
38+
COPY --chown=www-data:www-data composer.json composer.lock ./
39+
40+
# Install composer dependencies
41+
RUN composer install --optimize-autoloader --no-dev --no-scripts
42+
43+
# --- Application Code ---
44+
# Copy the rest of the application files
45+
COPY --chown=www-data:www-data . .
46+
47+
# Run composer post-install scripts
48+
RUN composer run-script post-autoload-dump
49+
50+
#
51+
# Production Stage
52+
#
53+
# This stage creates the final, lean image for production.
54+
#
55+
FROM serversideup/php:8.4-fpm-nginx
56+
57+
# Set working directory
58+
WORKDIR /var/www/html
59+
60+
# Switch to root to set correct permissions
61+
USER root
62+
63+
# Copy the entire application from the builder stage
64+
COPY --from=builder /var/www/html /var/www/html
65+
66+
# Ensure ownership is correct for the entire application directory
67+
RUN chown -R www-data:www-data /var/www/html
68+
69+
# Set specific permissions for storage and bootstrap/cache
70+
RUN chmod -R 775 /var/www/html/storage /var/www/html/bootstrap/cache
71+
72+
# Switch back to the non-privileged user
73+
USER www-data
74+
75+
# Expose port 8080 and start php-fpm
76+
EXPOSE 8080

.docker/nginx/conf.d/app.conf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
server {
2+
listen 80;
3+
index index.php index.html;
4+
error_log /var/log/nginx/error.log;
5+
access_log /var/log/nginx/access.log;
6+
root /var/www/html/public;
7+
location ~ \.php$ {
8+
try_files $uri =404;
9+
fastcgi_split_path_info ^(.+\.php)(/.+)$;
10+
fastcgi_pass app:9000;
11+
fastcgi_index index.php;
12+
include fastcgi_params;
13+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
14+
fastcgi_param PATH_INFO $fastcgi_path_info;
15+
}
16+
location / {
17+
try_files $uri $uri/ /index.php?$query_string;
18+
gzip_static on;
19+
}
20+
}

docker-compose.yml

Lines changed: 69 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,72 @@
1+
# docker-compose.yml for a Laravel application
2+
13
services:
2-
laravel.test:
3-
build:
4-
context: ./vendor/laravel/sail/runtimes/8.4
5-
dockerfile: Dockerfile
6-
args:
7-
WWWGROUP: '${WWWGROUP}'
8-
image: sail-8.4/app
9-
extra_hosts:
10-
- 'host.docker.internal:host-gateway'
11-
ports:
12-
- '${APP_PORT:-80}:80'
13-
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
14-
environment:
15-
WWWUSER: '${WWWUSER}'
16-
LARAVEL_SAIL: 1
17-
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
18-
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
19-
IGNITION_LOCAL_SITES_PATH: '${PWD}'
20-
volumes:
21-
- '.:/var/www/html'
22-
networks:
23-
- sail
24-
depends_on:
25-
- pgsql
26-
- redis
27-
- minio
28-
- mailpit
29-
pgsql:
30-
image: 'postgres:16'
31-
ports:
32-
- '${FORWARD_DB_PORT:-5432}:5432'
33-
environment:
34-
PGPASSWORD: '${DB_PASSWORD:-secret}'
35-
POSTGRES_DB: '${DB_DATABASE}'
36-
POSTGRES_USER: '${DB_USERNAME}'
37-
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
38-
volumes:
39-
- 'sail-pgsql:/var/lib/postgresql/data'
40-
- './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
41-
networks:
42-
- sail
43-
healthcheck:
44-
test: [ "CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}" ]
45-
retries: 3
46-
timeout: 5s
47-
redis:
48-
image: 'redis:alpine'
49-
ports:
50-
- '${FORWARD_REDIS_PORT:-6379}:6379'
51-
volumes:
52-
- 'sail-redis:/data'
53-
networks:
54-
- sail
55-
healthcheck:
56-
test:
57-
- CMD
58-
- redis-cli
59-
- ping
60-
retries: 3
61-
timeout: 5s
62-
minio:
63-
image: 'minio/minio:latest'
64-
ports:
65-
- '${FORWARD_MINIO_PORT:-9000}:9000'
66-
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
67-
environment:
68-
MINIO_ROOT_USER: sail
69-
MINIO_ROOT_PASSWORD: password
70-
volumes:
71-
- 'sail-minio:/data/minio'
72-
networks:
73-
- sail
74-
command: 'minio server /data/minio --console-address ":8900"'
75-
healthcheck:
76-
test:
77-
- CMD
78-
- curl
79-
- '-f'
80-
- 'http://localhost:9000/minio/health/live'
81-
retries: 3
82-
timeout: 5s
83-
mailpit:
84-
image: 'axllent/mailpit:latest'
85-
ports:
86-
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
87-
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
88-
networks:
89-
- sail
4+
# Application Service
5+
app:
6+
build:
7+
context: .
8+
dockerfile: ./.docker/Dockerfile
9+
image: your-laravel-app # You can name your image
10+
container_name: laravel-app
11+
restart: unless-stopped
12+
tty: true
13+
environment:
14+
SERVICE_NAME: app
15+
SERVICE_TAGS: dev
16+
working_dir: /var/www/html
17+
volumes:
18+
- ./:/var/www/html
19+
networks:
20+
- laravel
21+
22+
# Nginx Service
23+
nginx:
24+
image: nginx:alpine
25+
container_name: laravel-nginx
26+
restart: unless-stopped
27+
ports:
28+
- "8080:80"
29+
volumes:
30+
- ./:/var/www/html
31+
- ./docker/nginx/conf.d/:/etc/nginx/conf.d/
32+
networks:
33+
- laravel
34+
35+
# Database Service (MySQL)
36+
db:
37+
image: mysql:8.0
38+
container_name: laravel-db
39+
restart: unless-stopped
40+
environment:
41+
MYSQL_DATABASE: ${DB_DATABASE}
42+
MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
43+
MYSQL_PASSWORD: ${DB_PASSWORD}
44+
MYSQL_USER: ${DB_USERNAME}
45+
SERVICE_TAGS: dev
46+
SERVICE_NAME: mysql
47+
volumes:
48+
- dbdata:/var/lib/mysql
49+
ports:
50+
- "3306:3306"
51+
networks:
52+
- laravel
53+
54+
# Redis Service
55+
redis:
56+
image: redis:latest
57+
container_name: laravel-redis
58+
restart: unless-stopped
59+
ports:
60+
- "6379:6379"
61+
networks:
62+
- laravel
63+
64+
# Docker Networks
9065
networks:
91-
sail:
92-
driver: bridge
66+
laravel:
67+
driver: bridge
68+
69+
# Volumes
9370
volumes:
94-
sail-pgsql:
95-
driver: local
96-
sail-redis:
97-
driver: local
98-
sail-minio:
99-
driver: local
71+
dbdata:
72+
driver: local

docker-compose.yml_old

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
services:
2+
laravel.test:
3+
build:
4+
context: ./vendor/laravel/sail/runtimes/8.4
5+
dockerfile: Dockerfile
6+
args:
7+
WWWGROUP: '${WWWGROUP}'
8+
image: sail-8.4/app
9+
extra_hosts:
10+
- 'host.docker.internal:host-gateway'
11+
ports:
12+
- '${APP_PORT:-80}:80'
13+
- '${VITE_PORT:-5173}:${VITE_PORT:-5173}'
14+
environment:
15+
WWWUSER: '${WWWUSER}'
16+
LARAVEL_SAIL: 1
17+
XDEBUG_MODE: '${SAIL_XDEBUG_MODE:-off}'
18+
XDEBUG_CONFIG: '${SAIL_XDEBUG_CONFIG:-client_host=host.docker.internal}'
19+
IGNITION_LOCAL_SITES_PATH: '${PWD}'
20+
volumes:
21+
- '.:/var/www/html'
22+
networks:
23+
- sail
24+
depends_on:
25+
- pgsql
26+
- redis
27+
- minio
28+
- mailpit
29+
pgsql:
30+
image: 'postgres:16'
31+
ports:
32+
- '${FORWARD_DB_PORT:-5432}:5432'
33+
environment:
34+
PGPASSWORD: '${DB_PASSWORD:-secret}'
35+
POSTGRES_DB: '${DB_DATABASE}'
36+
POSTGRES_USER: '${DB_USERNAME}'
37+
POSTGRES_PASSWORD: '${DB_PASSWORD:-secret}'
38+
volumes:
39+
- 'sail-pgsql:/var/lib/postgresql/data'
40+
- './vendor/laravel/sail/database/pgsql/create-testing-database.sql:/docker-entrypoint-initdb.d/10-create-testing-database.sql'
41+
networks:
42+
- sail
43+
healthcheck:
44+
test: [ "CMD", "pg_isready", "-q", "-d", "${DB_DATABASE}", "-U", "${DB_USERNAME}" ]
45+
retries: 3
46+
timeout: 5s
47+
redis:
48+
image: 'redis:alpine'
49+
ports:
50+
- '${FORWARD_REDIS_PORT:-6379}:6379'
51+
volumes:
52+
- 'sail-redis:/data'
53+
networks:
54+
- sail
55+
healthcheck:
56+
test:
57+
- CMD
58+
- redis-cli
59+
- ping
60+
retries: 3
61+
timeout: 5s
62+
minio:
63+
image: 'minio/minio:latest'
64+
ports:
65+
- '${FORWARD_MINIO_PORT:-9000}:9000'
66+
- '${FORWARD_MINIO_CONSOLE_PORT:-8900}:8900'
67+
environment:
68+
MINIO_ROOT_USER: sail
69+
MINIO_ROOT_PASSWORD: password
70+
volumes:
71+
- 'sail-minio:/data/minio'
72+
networks:
73+
- sail
74+
command: 'minio server /data/minio --console-address ":8900"'
75+
healthcheck:
76+
test:
77+
- CMD
78+
- curl
79+
- '-f'
80+
- 'http://localhost:9000/minio/health/live'
81+
retries: 3
82+
timeout: 5s
83+
mailpit:
84+
image: 'axllent/mailpit:latest'
85+
ports:
86+
- '${FORWARD_MAILPIT_PORT:-1025}:1025'
87+
- '${FORWARD_MAILPIT_DASHBOARD_PORT:-8025}:8025'
88+
networks:
89+
- sail
90+
networks:
91+
sail:
92+
driver: bridge
93+
volumes:
94+
sail-pgsql:
95+
driver: local
96+
sail-redis:
97+
driver: local
98+
sail-minio:
99+
driver: local

0 commit comments

Comments
 (0)