Last active
September 3, 2025 16:26
-
-
Save alastairmccormack/cfc20722efef1c48d558571136b4173c to your computer and use it in GitHub Desktop.
A docker compose file for phpIPAM with MariaDB backend. DB is initialised ready to go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## docker-compose.yaml | |
| # phpIPAM with MariaDB backend | |
| # | |
| # Requires a .env file in the same directory with: | |
| # IPAM_DATABASE_NAME=phpipam | |
| # IPAM_DATABASE_USER=phpipam | |
| # IPAM_DATABASE_PASS=change-me-app | |
| # | |
| # access phpIPAM at http://localhost:8080 | |
| # Admin user: admin / password: ipamadmin | |
| services: | |
| mariadb: | |
| image: mariadb:10.6 | |
| container_name: phpipam-mariadb | |
| environment: | |
| MYSQL_ROOT_PASSWORD: change-me-root | |
| MYSQL_USER: ${IPAM_DATABASE_USER} # from .env | |
| MYSQL_PASSWORD: ${IPAM_DATABASE_PASS} | |
| MYSQL_DATABASE: ${IPAM_DATABASE_NAME} | |
| TZ: Europe/London | |
| volumes: | |
| - db_data:/var/lib/mysql | |
| networks: | |
| - db_net | |
| healthcheck: | |
| test: ["CMD-SHELL", "mysqladmin ping -h localhost -uroot -p$$MYSQL_ROOT_PASSWORD | grep -q 'mysqld is alive'"] | |
| interval: 10s | |
| timeout: 5s | |
| retries: 10 | |
| phpipam: | |
| image: phpipam/phpipam-www:latest | |
| container_name: phpipam-www | |
| depends_on: | |
| mariadb: | |
| condition: service_healthy | |
| environment: | |
| IPAM_DATABASE_HOST: mariadb | |
| IPAM_DATABASE_USER: ${IPAM_DATABASE_USER} # from .env | |
| IPAM_DATABASE_PASS: ${IPAM_DATABASE_PASS} | |
| IPAM_DATABASE_NAME: ${IPAM_DATABASE_NAME} | |
| TZ: Europe/London | |
| IPAM_DISABLE_INSTALLER: 1 | |
| ports: | |
| - "8080:80" | |
| networks: | |
| - app_net | |
| - db_net # shared only with MariaDB for back-end comms | |
| phpipam-cron: | |
| image: phpipam/phpipam-cron:latest | |
| container_name: phpipam-cron | |
| depends_on: | |
| mariadb: | |
| condition: service_healthy | |
| environment: | |
| IPAM_DATABASE_HOST: mariadb | |
| IPAM_DATABASE_USER: ${IPAM_DATABASE_USER} # from .env | |
| IPAM_DATABASE_PASS: ${IPAM_DATABASE_PASS} | |
| IPAM_DATABASE_NAME: ${IPAM_DATABASE_NAME} | |
| networks: | |
| - db_net # cron only needs DB access (no web exposure) | |
| db-init: | |
| image: phpipam/phpipam-www:latest | |
| depends_on: | |
| mariadb: | |
| condition: service_healthy | |
| networks: [db_net] | |
| restart: "no" # don't restart this one-shot job | |
| entrypoint: ["/bin/sh","-c"] | |
| command: > | |
| 'set -eu; | |
| MARIADB_CMD="mariadb --skip-ssl -u$${IPAM_DATABASE_USER} -p$${IPAM_DATABASE_PASS} -hmariadb $${IPAM_DATABASE_NAME}"; | |
| COUNT=$($${MARIADB_CMD} -Nse "SELECT COUNT(*) FROM information_schema.tables WHERE table_schema=\"phpipam\" AND table_name=\"settings\";"); | |
| if [ "$$COUNT" -eq 0 ]; then | |
| echo "=> Installing phpIPAM database schema..."; | |
| $${MARIADB_CMD} < /phpipam/db/SCHEMA.sql; | |
| echo "=> Done!"; | |
| fi; | |
| ' | |
| environment: | |
| IPAM_DATABASE_HOST: mariadb | |
| IPAM_DATABASE_USER: ${IPAM_DATABASE_USER} # from .env | |
| IPAM_DATABASE_PASS: ${IPAM_DATABASE_PASS} | |
| IPAM_DATABASE_NAME: ${IPAM_DATABASE_NAME} | |
| volumes: | |
| db_data: | |
| networks: | |
| app_net: | |
| driver: bridge | |
| db_net: | |
| driver: bridge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment