Docker setup for nextcloud

I have Dockerfile:

# syntax=docker/dockerfile:1

# Source image (update php version when needed)
FROM php:8.3.12-apache

# PHP ini path for upload config
ARG UPLOADS_INI="/usr/local/etc/php/conf.d/uploads.ini"

# Enable mod_rewrite, install dependencies, PHP extensions, and xdebug in one layer
# Clean up apt cache to reduce image size
RUN a2enmod rewrite \
    && apt-get update \
    && apt-get install -y --no-install-recommends libzip-dev libmariadb-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev \
    && docker-php-ext-install mysqli pdo_mysql gd zip \
    && docker-php-ext-enable mysqli pdo_mysql gd \
    && printf "upload_max_filesize = 128M\npost_max_size = 128M\n" > "${UPLOADS_INI}" \
    && printf "memory_limit = -1\n" >> "${UPLOADS_INI}" \
    && pecl install xdebug-3.4.1 \
    && docker-php-ext-enable xdebug \
    && apt-get purge -y --auto-remove libmariadb-dev \
    && rm -rf /var/lib/apt/lists/* /tmp/pear

USER www-data

and compose.yaml:

name: ${PROJECT_NAME}
networks:
  default:
    name: ${NETWORK_NAME}
    driver: bridge

services:
  server:
    container_name: ${PROJECT_NAME}-web
    extra_hosts:
      host.docker.internal: host-gateway  
    build:
      context: .
    restart: no
    user: "${UID}:${GID}"
    ports: ["9080:80"]
    volumes:
      - ../htdocs/:/var/www/html
      - ../nextcloud-data/:/var/www/html/data
      - ../logs/:/var/www/logs
      - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini

  db:
    container_name: ${PROJECT_NAME}-db

    image: mariadb
    volumes: ["db:/var/lib/mysql:Z"]
    restart: no
    ports: ["${MARIADB_PORT}:3306"]
    environment:
      - MARIADB_ROOT_PASSWORD=${MARIADB_ROOTPASSWORD}
      - MARIADB_DATABASE=${MARIADB_DATABASE}
      - MARIADB_USER=${MARIADB_USER}
      - MARIADB_PASSWORD=${MARIADB_PASSWORD}
 
volumes:
  db:

and .env:

PROJECT_NAME=nc-dev
NETWORK_NAME=${PROJECT_NAME}-network
MARIADB_PORT=3306
MARIADB_ROOTPASSWORD=guessme
MARIADB_DATABASE=nextcloud
MARIADB_USER=nextcloud
MARIADB_PASSWORD=nextcloud

If I start this first thing I get this:

PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'nextcloud.oc_appconfig' doesn't exist in

which makes sense with an empty database. I can connect to the database but not tables are setup.

solved. there was a spurious /config/config.php from a previous attempt .

So steps to reset the server:

  • remove the containers
  • remove the volume nc-dev-db
  • remove the /config/config.php file
  • remove the nextcloud-data folder