Problem with docker-compose file configuring Nextcloud & MariaDB images

Hi,

I’m a newbie using Docker Compose 1.17.1 (within a Plesk-administered VPS running Ubuntu 18.04), and I have been trying to get a container going with a Nextcloud image (15.0.4 for now) and a MariaDB image (10.4.2 for now) configured according to the following yaml file:

> version: '3' 
> 
> services:
> 
>   db:
>     image: mariadb:latest
>     container_name: nextcloud-mariadb
>     networks:
>       - nextcloud_network
>     volumes:
>       - /opt/mariadb/data:/var/lib/mysql
>       - /opt/mariadb/log:/var/log/mysql
>       - /opt/mariadb/config:/etc/mysql/conf.d
>       - /etc/localtime:/etc/localtime:ro
>     environment:
>       - MYSQL_ROOT_PASSWORD=secret
>       - MYSQL_USER=mariadb_user
>       - MYSQL_PASSWORD=secret
>       - MYSQL_DATABASE=nextcloud
>     restart: unless-stopped
>   
>   app:
>     image: nextcloud:latest
>     container_name: nextcloud
>     networks:
>       - nextcloud_network
>     depends_on:
>       - db
>     volumes:
>       - /opt/nextcloud/www:/var/www/html
>       - /opt/nextcloud/data:/var/www/html/data/
>       - /opt/nextcloud/config:/var/www/html/config/
>       - /opt/nextcloud/apps:/var/www/html/apps/
>       - /opt/nextcloud/custom_apps:/var/www/html/custom_apps/
>       - /opt/nextcloud/themes:/var/www/html/themes/
>       - /etc/localtime:/etc/localtime:ro
>     environment:
>       - MYSQL_HOST=db
>     restart: unless-stopped
> 
> volumes:
>   nextcloud:
>   db:
> 
> networks:
>   nextcloud_network:

Each local image seems to work fine when I try a docker run command on them separately, but when I try a docker-compose up -d command using the above yaml file, the MariaDB server does not want to initialize properly. The log shows this problem:

> [ERROR] mysqld: File '/var/log/mysql/mariadb-bin.index' not found (Errcode: 13 "Permission denied")

When I enter docker ps -a, MariaDB comes up as Restarting (1). Since the MariaDB image doesn’t give me this problem when I run it as a standalone docker container, my guess is that it’s not an issue with the image itself but rather it’s something I’m doing wrong with my docker-compose file.

I tried asking for help on the Nextcloud forum, and received advice to change owner & permission settings for /var/log/mysql. I did that, and did the same for /opt/mariadb/log. Those settings now look like the following:

drwxrwxr-x 2 mysql mysql 4096 Feb 25 06:33 mysql (/var/log/mysql)
drwxrwxr-x 2 mysql mysql 4096 Feb 16 23:54 log (/opt/mariadb/log)

The person helping me at the Nextcloud forum suggested that I would need to change owner & permission settings for /opt/mariadb/log from within the container itself by way of a docker exec command. I tried docker exec -it <container name> /bin/bash as advised, but got this response:

> Error response from daemon: Container <containerID> is restarting, wait until the container is running

I seem to be caught in a newbie Catch-22, and I’m not sure what to try next. Any insight is appreciated.

Is MariaDB running as the user mysql in the container??

When you run it as a standalone container, do you start it with:

docker run -d \
  --name nextcloud-mariadb \
  -v /opt/mariadb/data:/var/lib/mysql \
  -v /opt/mariadb/log:/var/log/mysql \
  -v /opt/mariadb/config:/etc/mysql/conf.d \
  -v /etc/localtime:/etc/localtime:ro \
   ....
   mariadb:latest

Thanks very much for the reply. I’m embarrassed to admit that in my newbiness I just entered a standard docker run -d --name nextcloud-mariadb mariadb:latest command. When I added those parameters for mounting other directories, I did encounter the same “permission denied” error as happened with the docker-compose command I tried with the yaml file above.

I’m not sure how to check which user MariaDB is running as inside the container. After entering the run command again I tried entering docker attach nextcloud-mariadb, but got this response:

You cannot attach to a stopped container, start it first

After that I tried docker start nextcloud-mariadb, which returned nextcloud-mariadb, and then entered docker attach nextcloud-mariadb again but got the same response. A docker ps -a displayed the nextcloud-mariadb container as Exited (1).

Thanks again for any help to get me past my early misunderstandings.

I apologize for the gratuitous thread bump. I’m still struggling with this docker-compose project. I am eager to learn enough about Docker and Docker Compose to make it a part of my regular software management process.

Does anyone have a tip about the origins of my newbie error outlined in the posts above? Thanks for any insight.