Docker-compose: Nextcloud, Apache, MariaDB

Hi,
I’m trying to get Nextcloud working with an Apache webserver and MariaDB using docker-compose. I’m basically using the example shown in the Nextcloud quick reference on Docker Hub. This is my docker-compose file:

version: '2'

volumes:
  nextcloud:
  db:

services:
  db:
    image: mariadb
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: always
    volumes:
      - db:/var/lib/mysql
    container_name: mariadb
    environment:
      - MYSQL_ROOT_PASSWORD=ABC123
      - MYSQL_PASSWORD=DEF456
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: nextcloud
    ports:
      - 8000:80
    links:
      - db
    container_name: nextcloud
    volumes:
      - nextcloud:/var/www/html
    restart: always

When I connect to Nextcloud, this is I what I see:

I’m not sure what I was expecting to see, but I guess after defining the MariaDB environment in the compose file, I wasn’t expecting to enter the details again. Do I? If so, what do I enter for localhost:port? I’m connecting to the Nextcloud instance using 10.1.1.18:8000.

yes. because you only created the database in the mariadb container. you would have to set also set the environment variables for the nextcloud container.

db or mariadb

it’s the name of the container. internal docker dns.

1 Like

Thanks Reiner, that makes sense :thinking:. So, I enter the details and get a little further. I see this screen. I assume it’s the MYSQL_PASSWORD I use for the database password, but I’ve tried both passwords anyway with similar results.

you have to add

    environment:
      - MYSQL_PASSWORD=DEF456
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_HOST=mariadb

into the app: section of the docker compose file.

(i think it’s mariadb instead of db since you use container_name: mariadb)

Interestingly, I did have that in at one point, but decided to take it out to match as closely the quick reference example provided. I’ve put it back with, but the result is exactly the same.

I’ve had a look around the forum for clues, but most of the relevant threads seem to want me to ‘roll up my sleeves and get under the hood’ to fix the problem. I’m trying to avoid that with the quick reference examples if I can.

EDIT: It appears that the referred quick reference example doesn’t work as stated for the Docker version of Nextcloud 19.

to be honest i don’t use this. neither the env vars nor the web page.

i use occ:

docker exec --user www-data nextcloud php occ  maintenance:install --.....

Thanks for your time Reiner. It’s much appreciated. I think I might be getting somewhere. I’ll post back once I get a handle on what’s going on.

Right here’s the verdict… The example in the Nextcloud quick reference on Docker Hub does work!

However, there are two key missing details required to make it work.

  1. localhost = db as per @Reiner_Nippes earlier post above.

This detail is in the quick reference guide, but I missed it.

  1. Patience!

It takes a while for the MariaDB container to do its thing. What gave it away for me was the ebb and flow of disk activity I was hearing from the server. It can take as long as five to 10 minutes for the container to settle. I suggest you go and make a nice cup of tea and have a biscuit while waiting.

If you’re impatient (like me!), you can trace what the container is doing with sudo docker logs -f mariadb (replace mariadb with whatever is the name of your db container; Ctrl-C to exit). You’ll be able to log in after you see the lines highlighted in the image below.