Restructure Docker for Dokploy deployment

- Copy app code into PHP image, sync to shared volume at startup
- Use named volume (app_code) shared between app and nginx
- Build nginx image with embedded config (no bind mounts)
- Add .dockerignore to optimize image build
- Build context moved to project root for both services
This commit is contained in:
root
2026-04-05 20:09:12 +02:00
parent 3abde23629
commit 1632b568af
5 changed files with 50 additions and 9 deletions

22
.dockerignore Normal file
View File

@@ -0,0 +1,22 @@
.git
.gitignore
.env
vendor
node_modules
storage/logs/*
storage/framework/cache/*
storage/framework/sessions/*
storage/framework/views/*
bootstrap/cache/*
public/build
public/storage
db_data
redis_data
docker-compose.yml
docker-compose.override.yml
README.md
TerManager2_v2.md
.idea
.vscode
*.swp
*.swo

View File

@@ -1,12 +1,13 @@
services:
app:
build:
context: ./docker/php
context: .
dockerfile: docker/php/Dockerfile
container_name: termanager2_app
restart: unless-stopped
working_dir: /var/www/html
volumes:
- .:/var/www/html
- app_code:/var/www/html
- storage_data:/var/www/html/storage/app
networks:
- termanager2
@@ -19,14 +20,15 @@ services:
- PHP_OPCACHE_VALIDATE_TIMESTAMPS=1
nginx:
image: nginx:1.25-alpine
build:
context: .
dockerfile: docker/nginx/Dockerfile
container_name: termanager2_nginx
restart: unless-stopped
ports:
- "${APP_PORT:-8080}:80"
volumes:
- .:/var/www/html:ro
- ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
- app_code:/var/www/html:ro
networks:
- termanager2
depends_on:
@@ -81,6 +83,8 @@ services:
- termanager2
volumes:
app_code:
driver: local
db_data:
driver: local
redis_data:

2
docker/nginx/Dockerfile Normal file
View File

@@ -0,0 +1,2 @@
FROM nginx:1.25-alpine
COPY docker/nginx/default.conf /etc/nginx/conf.d/default.conf

View File

@@ -42,14 +42,17 @@ RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash - \
# Set working directory
WORKDIR /var/www/html
# Copy application code to staging area
COPY . /app-src/
# Copy PHP configuration
COPY php.ini /usr/local/etc/php/conf.d/custom.ini
COPY docker/php/php.ini /usr/local/etc/php/conf.d/custom.ini
# Copy PHP-FPM pool config
COPY www.conf /usr/local/etc/php-fpm.d/www.conf
COPY docker/php/www.conf /usr/local/etc/php-fpm.d/www.conf
# Copy entrypoint
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
COPY docker/php/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
EXPOSE 9000

View File

@@ -6,7 +6,17 @@ echo " TerManager2 - Entrypoint"
echo "========================================="
# -----------------------------------------------
# 0. Create required directories
# 0. Sync application code from image to volume
# -----------------------------------------------
if [ ! -f /var/www/html/artisan ]; then
echo "[*] Syncing application code to volume..."
cp -a /app-src/. /var/www/html/
else
echo "[✓] Application code already in volume."
fi
# -----------------------------------------------
# 0b. Create required directories
# -----------------------------------------------
mkdir -p storage/framework/{cache,sessions,views}
mkdir -p storage/logs