How to enable MariaDB 4-byte support in docker

In the manual it is missing the information for how to do this if you are using docker images:

you create a nextcloud-mysql.cnf file on your host and map it via volume into the container.

similar to: Cannot Hook Into PHP Folder via Docker

you can find this also in the mariadb readme on docker hub:

Using a custom MySQL configuration file

The startup configuration is specified in the file /etc/mysql/my.cnf, and that file in turn includes any files found in the /etc/mysql/conf.d directory that end with .cnf. Settings in files in this directory will augment and/or override settings in /etc/mysql/my.cnf. If you want to use a customized MySQL configuration, you can create your alternative configuration file in a directory on the host machine and then mount that directory location as /etc/mysql/conf.d inside the mariadb container.

If /my/custom/config-file.cnf is the path and name of your custom configuration file, you can start your mariadb container like this (note that only the directory path of the custom config file is used in this command):

$ docker run --name some-mariadb -v /my/custom:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=my-secret-pw -d mariadb:tag

This will start a new container some-mariadb where the MariaDB instance uses the combined startup settings from /etc/mysql/my.cnf and /etc/mysql/conf.d/config-file.cnf, with settings from the latter taking precedence.

You can run a bash shell on the container and follow the same procedure, I think. I did this on mine but was some time ago.

wouldn’t that be vanish again, if you update the container?

Only if you throw the baby out with the bath water…

“to lose valuable ideas or things in your attempt to get rid of what is not wanted”???

I thought, sometimes, you recreate the container, because all data that are specific should be mounted via volumes, to survive such a re-creation of the container?

If you use a Docker container database, you need a permanent volume mount so your database is persistent. Then you delete and recreate the container, and all the software in the image is updated, but the database remains.

maybe you can clarify how? which script? in which volume will it fix the 4-byte issue?

To open a shell on a container:

docker exec -it container /bin/bash

Then you can get into MySQL locally. As for the volume, you need either a named volume or host folder mounted where the database is so the data can be re-attached when you cycle the container.

All of that is covered in detail here.

I’m more of a docker-compose user but you can just use

You can see what a config should look like at Nextcloud Database Configuration. Although your config could vary depending on your usecase.
You should look into the examples from the nextcloud docker repo if you want to get into using docker-compose files.

If you want to go docker-compose, this is how it should look like (could be slimmed down if you want to, look at examples from the repo and take what you need from this)
version: '3'

  nextcloud_data: #persistent
    external: true
  nextcloud_config: #persistent
    external: true
  nextcloud_db: #persistent
    external: true
  nextcloud_apps: #persistent
    external: true

    container_name: nextcloud_db
    image: mariadb #jsurf/rpi-mariadb
    restart: always
      - nextcloud_db:/var/lib/mysql
      - /my/path/to/myconfig.cnf:/etc/mysql/conf.d/myconfig.cnf:ro #your mysql config

    container_name: nextcloud
    image: nextcloud:apache
      - db
      - nextcloud:/var/www/html
      - nextcloud_data:/var/www/html/data
      - nextcloud_config:/var/www/html/config
      - nextcloud_apps:/var/www/html/custom_apps
      #- /my/path/to/my.config.php:/var/www/html/config/my.config.php
     - MY_SQL_HOST=db
    restart: always

my mysql config looks currently like this (not the missing includes from the example at the first link, they would create an infinite inclusion loop):

innodb_buffer_pool_size = 128M
innodb_buffer_pool_instances = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 32M
innodb_max_dirty_pages_pct = 90
query_cache_type = 1
query_cache_limit = 2M
query_cache_min_res_unit = 2k
query_cache_size = 32M
tmp_table_size= 64M
max_heap_table_size= 64M
slow-query-log = 1
slow-query-log-file = /var/log/mysql/slow.log
long_query_time = 1

join_buffer_size = 256k

key_buffer = 64M

default-character-set = utf8mb4

character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
transaction_isolation = READ-COMMITTED
binlog_format = ROW

I just used this part of your solution:

I already use a docker-compose file, so I just added that line to my docker-compose.yaml and adapted the paths and added your mariadb config file (Note: I changed the setting barracuda to Baracuda, not sure if that is important). But just adding your mysql config file is not enough, you also need to convert the database with the commands from the manual:

I adapted the commands so they are called via docker exec:

docker exec $DB_CONTAINER mysql nextcloud -p$MYSQL_ROOT_PASSWORD -e "show variables like 'innodb_file_format';"
docker exec --user www-data $APP_CONTAINER php occ maintenance:mode --on
docker exec $DB_CONTAINER mysql nextcloud -p$MYSQL_ROOT_PASSWORD -e "ALTER DATABASE nextcloud CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;"
docker exec --user www-data $APP_CONTAINER php occ config:system:set mysql.utf8mb4 --type boolean --value="true"
docker exec --user www-data $APP_CONTAINER php occ maintenance:repair ; \
docker exec --user www-data $APP_CONTAINER php occ maintenance:mode --off