Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
NextCloud with Maria DB docker-compose file
# NextCLoud with MariaDB/MySQL
#
# Access via "http://localhost:80" (or "http://$(docker-machine ip):80" if using docker-machine)
#
# During initial NextCLoud setup, select "Storage & database" --> "Configure the database" --> "MySQL/MariaDB"
# Database user: nextcloud
# Database password: nextcloud
# Database name: ncdb
# Database host: replace "localhost" with "maria-db" the same name as the data base container name.
#
#
# The reason for the more refined data persistence in the volumes is because if you were to
# use just the the '/var/www/html' then everytime you would want/need to update/upgrade
# NextCloud you would have to go into the volume on the host machine and delete 'version.php'
#
version: '2'
services:
nextcloud:
container_name: nextcloud
restart: unless-stopped
image: nextcloud
ports:
- 80:80
volumes:
- /containers/cloud/nextcloud/apps:/var/www/html/apps
- /containers/cloud/nextcloud/config:/var/www/html/config
- /containers/cloud/nextcloud/data:/var/www/html/data
depends_on:
- db
db:
container_name: maria-db
restart: unless-stopped
image: mariadb
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: ncdb
MYSQL_USER: nextcloud
MYSQL_PASSWORD: nextcloud
volumes:
- /containers/cloud/mariadb:/var/lib/mysql
@timsayshey
Copy link

timsayshey commented Jan 19, 2021

Follow the instructions but after I submitted the initial form I get the following response:

Error
Error while trying to create admin user: Failed to connect to the database: An exception occurred in driver: SQLSTATE[HY000] [1045] Access denied for user 'nextcloud'@'172.21.0.3' (using password: YES)

@Domepo
Copy link

Domepo commented Oct 29, 2021

Port

To bypass some conflicts you need to change the port to 8080:80.

    ports:
      - 8080:80

Mariadb

If you get this message:

Doctrine\DBAL\Exception\DriverException: An exception occurred while executing a query: SQLSTATE[HY000]: General error: 4047 InnoDB refuses to write tables with ROW_FORMAT=COMPRESSED or KEY_BLOCK_SIZE.

You need to change the docker-compose.yml file.
Nextcloud has some problems with the new MariaDB versions (ROW_FORMAT = COMPRESSED).

To fix this, add this line to your docker-compose.yml

command: --innodb-read-only-compressed=OFF

New docker-compose.yml

# NextCLoud with MariaDB/MySQL
#
# Access via "http://localhost:80" (or "http://$(docker-machine ip):8080" if using docker-machine)
#
# During initial NextCLoud setup, select "Storage & database" --> "Configure the database" --> "MySQL/MariaDB"
# Database user: nextcloud 
# Database password: nextcloud
# Database name: ncdb
# Database host: replace "localhost" with "maria-db" the same name as the data base container name.
#
#
# The reason for the more refined data persistence in the volumes is because if you were to
# use just the the '/var/www/html' then everytime you would want/need to update/upgrade
# NextCloud you would have to go into the volume on the host machine and delete 'version.php'
#

version: '2'

services:

  nextcloud:
    container_name: nextcloud
    restart: unless-stopped
    image: nextcloud
    ports:
      - 8080:80 #Port change
    volumes:
      - /containers/cloud/nextcloud/apps:/var/www/html/apps
      - /containers/cloud/nextcloud/config:/var/www/html/config
      - /containers/cloud/nextcloud/data:/var/www/html/data
    depends_on:
      - db

  db:
    container_name: maria-db
    restart: unless-stopped
    image: mariadb
    command: --innodb-read-only-compressed=OFF #Maria-DB fix
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: ncdb
      MYSQL_USER: nextcloud
      MYSQL_PASSWORD: nextcloud
    volumes:
      - /containers/cloud/mariadb:/var/lib/mysql
      

@D-ctrl
Copy link

D-ctrl commented Nov 29, 2021

Thank you! Worked like a charm.

@anu1097
Copy link

anu1097 commented Jan 27, 2022

Hi, I have a concern with this line -

    volumes:
      - /containers/cloud/mariadb:/var/lib/mysql

It works fine when the /container is part of the same storage filesystem as the docker-compose file.
But if connect an external drive to store media and replace /containers/cloud/mariadb with /mnt/usb0/containers/cloud/mariadb

It give me permission issue. It tries to change ownership of the location and fails. How do I handle it ?

I can't run nextcloud on my primary storage drive as it will run out of storage memory pretty soon.

@nmfreitas
Copy link

nmfreitas commented Jun 1, 2022

Hi @anu1097, probably you need to give permissions to that folder Tray 'sudo chmod 775 /mnt/usb0/containers/cloud/mariadb'
If this didn't work you can try 'sudo chmod 777 /mnt/usb0/containers/cloud/mariadb' but "777" is not recommended.

@raverdave-2k
Copy link

raverdave-2k commented Aug 7, 2022

Hi,

Trying to get this setup but I get this when entering the databse information during the initial setup.

SQLSTATE[HY000] [1130] Host '172.28.0.3' is not allowed to connect to this MariaDB server

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment