mjl.
← All articles

Podman Multi-Container Web and Database Stacks

podmancontainersphpmariadbnetworking

This article extends Podman Volumes and Web Containers. The web and database services have separate lifecycles and communicate over a private named network.

Create a network and database volume

podman network create app-net
podman volume create mariadb-data

Start MariaDB

Use development-only values here. In real deployments, inject secrets through a managed secret store or protected environment file.

podman run --name db --detach \
  --network app-net \
  --volume mariadb-data:/var/lib/mysql \
  --env MARIADB_DATABASE=app \
  --env MARIADB_USER=app \
  --env MARIADB_PASSWORD=change-me-now \
  --env MARIADB_ROOT_PASSWORD=change-root-password \
  docker.io/library/mariadb:11

Do not publish 3306 unless a host-side client must connect. Containers on app-net can reach MariaDB by the name db.

Start the web container

The application image must contain the required PHP extensions and application files. Use a custom Containerfile when it does not.

podman run --name web --detach \
  --network app-net \
  --publish 8080:80 \
  --volume "$HOME/containers/app:/var/www/html:ro" \
  docker.io/library/php:8.3-apache

In PHP, connect to host db and port 3306, not to a guessed IP and not to the published host port.

Verify readiness

podman ps
podman logs db
podman exec db mariadb -uapp -pchange-me-now app -e 'SELECT 1;'
curl http://127.0.0.1:8080

MariaDB may need time to initialise. A production application should implement retries and health checks rather than assuming that process start means database readiness.