Skip to content

Commit b59c8cc

Browse files
Containerize application with Podman (Apache + MariaDB)
- Added Dockerfile for PHP 8.2 Apache service with pdo_mysql extension. - Added docker-compose.yml defining 'web' and 'db' services. - Updated save_highscore.php to use environment variables for DB connection with fallback to localhost. - Added README_PODMAN.md with instructions in German.
1 parent d883546 commit b59c8cc

File tree

4 files changed

+78
-4
lines changed

4 files changed

+78
-4
lines changed

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM php:8.2-apache
2+
3+
# Install PDO MySQL extension
4+
RUN docker-php-ext-install pdo pdo_mysql
5+
6+
# Copy application source
7+
COPY . /var/www/html/

README_PODMAN.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Anleitung zur Verwendung mit Podman
2+
3+
Dieses Projekt kann mit Podman und Podman Compose ausgeführt werden.
4+
5+
## Voraussetzungen
6+
7+
- [Podman](https://podman.io/)
8+
- [Podman Compose](https://github.com/containers/podman-compose) (oder Docker Compose)
9+
10+
## Starten der Container
11+
12+
Um die Anwendung zu starten, führen Sie den folgenden Befehl im Hauptverzeichnis des Projekts aus:
13+
14+
```bash
15+
podman-compose up --build
16+
```
17+
18+
Oder, falls Sie `docker-compose` verwenden:
19+
20+
```bash
21+
docker-compose up --build
22+
```
23+
24+
Die Anwendung ist dann unter [http://localhost:8080](http://localhost:8080) erreichbar.
25+
26+
## Datenbank
27+
28+
Die Datenbank wird automatisch mit der Datei `router_game.sql` initialisiert.
29+
Die Datenbankdaten werden in einem Volume `db_data` gespeichert.
30+
31+
## Stoppen der Container
32+
33+
Um die Container zu stoppen und zu entfernen:
34+
35+
```bash
36+
podman-compose down
37+
```

docker-compose.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
version: '3.8'
2+
3+
services:
4+
db:
5+
image: mariadb:10
6+
container_name: router_game_db
7+
environment:
8+
MYSQL_ROOT_PASSWORD: rootpassword
9+
MYSQL_DATABASE: router_game
10+
MYSQL_USER: router_user
11+
MYSQL_PASSWORD: router_password
12+
volumes:
13+
- ./router_game.sql:/docker-entrypoint-initdb.d/init.sql
14+
- db_data:/var/lib/mysql
15+
16+
web:
17+
build: .
18+
container_name: router_game_web
19+
ports:
20+
- "8080:80"
21+
environment:
22+
DB_HOST: db
23+
DB_NAME: router_game
24+
DB_USER: router_user
25+
DB_PASSWORD: router_password
26+
depends_on:
27+
- db
28+
29+
volumes:
30+
db_data:

save_highscore.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// save_highscore.php
33

44
// Database configuration
5-
$host = 'localhost';
6-
$dbname = 'router_game';
7-
$username = 'root';
8-
$password = '';
5+
$host = getenv('DB_HOST') ?: 'localhost';
6+
$dbname = getenv('DB_NAME') ?: 'router_game';
7+
$username = getenv('DB_USER') ?: 'root';
8+
$password = getenv('DB_PASSWORD') ?: '';
99

1010
// Create connection
1111
try {

0 commit comments

Comments
 (0)