docker compose exemplified, .env integration

This commit is contained in:
Reindl David (IT-PTR-CEN2-SL10) committed 2026-10-07 18:59:58 +02:00
1 parent b1284f6fa9
commit 42ef989fb7
6 files changed
+22 -5

No files matched your search

+1
View File
@@ -4,4 +4,5 @@ config/config.local.php
logs/app.log
agent-prompts
.env
docker-compose.yml
~*
+9
View File
@@ -115,6 +115,14 @@ CMD ["php", "-S", "0.0.0.0:8080", "-t", "public"]
```
### Docker Compose
Use the example template as the base for a local override:
```bash
cp docker-compose.example.yml docker-compose.yml
```
Then adapt the local values as needed:
```yaml
services:
password-generator:
@@ -132,6 +140,7 @@ services:
CORS_METHODS: "GET,POST,OPTIONS"
CORS_HEADERS: "Content-Type,Authorization"
volumes:
- ./.env:/var/www/html/.env:ro
- ./logs:/var/www/html/logs
restart: unless-stopped
```
+1 -1
View File
@@ -28,7 +28,7 @@ COPY . /var/www/html/
RUN composer install --no-dev --optimize-autoloader --no-interaction --prefer-dist \
&& mkdir -p logs \
&& chmod 755 logs \
&& cp -n .env.example .env \
&& if [ ! -f .env ]; then cp .env.example .env; fi \
&& chown -R www-data:www-data /var/www/html
EXPOSE 8080
+2 -1
View File
@@ -219,10 +219,11 @@ docker run --rm -p 8080:8080 --name password-generator password-generator:latest
### Docker Compose (project-local setup)
The repository includes a project-specific Compose file for local development and testing.
The repository ships a compose template rather than a committed local override. Copy it to a host-specific file before running locally.
```bash
cp .env.example .env
cp docker-compose.example.yml docker-compose.yml
cp config/config.example.json config/config.json
mkdir -p logs
@@ -20,6 +20,7 @@ services:
CORS_METHODS: "GET,POST,OPTIONS"
CORS_HEADERS: "Content-Type,Authorization"
volumes:
- ./.env:/var/www/html/.env:ro
- ./logs:/var/www/html/logs
- ./config/config.json:/var/www/html/config/config.json:ro
healthcheck:
+8 -3
View File
@@ -9,9 +9,14 @@ use Slim\Factory\AppFactory;
require __DIR__ . '/../vendor/autoload.php';
// Load environment variables
$dotenv = Dotenv\Dotenv::createImmutable(__DIR__ . '/../');
$dotenv->load();
// Load environment variables when a project .env file is present.
// Docker can provide these via env_file/environment as well; in that case
// we should not crash if the file is not mounted into the container.
$dotenvPath = __DIR__ . '/../';
if (is_file($dotenvPath . '.env')) {
$dotenv = Dotenv\Dotenv::createImmutable($dotenvPath);
$dotenv->safeLoad();
}
// Build DI container
$containerBuilder = new ContainerBuilder();