General question for official docker image of nextcloud

Hi,

i’m currently migrating my docker instances from the docker image wonderfall to the official docker image from nextcloud.

My previous process for upgrading the docker image (aka nextcloud) was to shut down all container from my docker-compose file and fire it up again with

docker-compose down && docker-compose up -d

This was working perfectly with the wonderfall image. But with the official docker image i’m getting problems of different types. As it seems each time the nextcloud container is fired up, it tries to perform an install. After my initial setup of all nextcloud container (nextcloud, redis, onlyoffice …) I’m getting the following types of errors after doing the above mentioned commands:

  • unable to connect to database (i overcome this one by delaying the start of the nextcloud container)
  • unable to install nextcloud, because the database already exists (yeah, i know)
  • any seemingly arbitary exceptions in the log (docker logs -f nextcloud)

I think i don’t need to go into the detail, because as the thread is more of a general question.

I know that upgrading the nextcloud works by stopping the container, performing a pull and restarting the container again. But how do i perform updates of my nextcloud docker-file, without triggering an install each time.
Let’s say i want to remount a volume, or attach an additional volume, is that possible without a complete docker-compose down?

Thanks,

BR,

Michael

I’m not familiar with wonderful, but I can tell you that I do docker-compose down, pull, and docker-compose up -d on mine using the official image, and this works fine.

You can fix this in docker-compose by making one container depend on the other. Then it will wait for the database container to come up before starting the Nextcloud container.

Hi Karl,

thanks for your response. I had the database already setup as dependency to my nextcloud container.
After running the command

docker-compose up -d && docker logs -f nextcloud

i get the log out put below. As a remark i’d like to denote, that i already ran an instance of nextcloud with this docker-compose file. Meaning, i have setup volumes that contain the data and configs. The log states the data directory is invalid, which is nonsens from my point of view, because it was already running before.

Here is my docker-compose file. Some docker volumes are created with the cifs driver from docker-netshare-volume.

I’d like to understand, why my container is behaving like this.

Thanks,

BR,

Michael


docker-compose

    version: '3'

services:
  nextcloud:
    image: nextcloud:16-apache
    container_name: nextcloud
    restart: on-failure
    environment:
      - TZ=Europe/Berlin
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=<supersecretpassword>
      - MYSQL_HOST=db
      - NEXTCLOUD_ADMIN_USER=admin  
      - NEXTCLOUD_ADMIN_PASSWORD=<supersecretpassword>
      - NEXTCLOUD_TRUSTED_DOMAINS=192.168.47.11 mydomain.de
      - REDIS_HOST=redis
    volumes:
      - data:/data
      - config:/var/www/html/config
      - apps:/var/www/html/custom_apps
    ports:
      - 47111:80
    depends_on:
      - db
      - redis
      - onlyoffice
    networks:
      - network
  onlyoffice:
    container_name: nextcloud_oo
    image: onlyoffice/documentserver:latest
    stdin_open: true
    restart: always
    ports:
      - 47112:80
    networks:
      - network
  redis:
    image: redis
    container_name: nextcloud_redis
    networks:
      - network
  db:
    image: mariadb:10
    container_name: nextcloud_db
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    restart: on-failure
    environment:
      - MYSQL_ROOT_PASSWORD=<supersecretpassword>
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=<supersecretpassword>
    volumes:
      - db:/var/lib/mysql
    networks:
      - network
networks:
  network:
    driver: 'bridge'
volumes:
  db:
  data:
    driver: cifs
    driver_opts:
        share: mydomain.de/path/to/nextcloud/data
        cifsopts: vers=3.0,uid=33,gid=33,dir_mode=0770,file_mode=0770,user=user,password=password
  config:
    driver: cifs
    driver_opts:
        share: mydomain.de/path/to/nextcloud/config
        cifsopts: vers=3.0,uid=33,dir_mode=0755,file_mode=0755,user=user,password=password
  apps:

log output

… of docker logs -f nextcloud

Configuring Redis as session handler
Initializing nextcloud 16.0.3.0 ...
Initializing finished
New nextcloud instance
Installing with MySQL database
starting nextcloud installation
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/html/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/html/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/html/occ(11): require_once('/var/www/html/c...')
#2 {main}retrying install...
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/html/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/html/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/html/occ(11): require_once('/var/www/html/c...')
#2 {main}retrying install...
Your data directory is invalid
Ensure there is a file called ".ocdata" in the root of the data directory.

An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /var/www/html/lib/private/Console/Application.php:166
Stack trace:
#0 /var/www/html/console.php(96): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /var/www/html/occ(11): require_once('/var/www/html/c...')
#2 {main}retrying install...

you have no volume for /var/www/html. so each time you update your container you get a full install.

add - nextclound:/var/www/html to the volumes of the nextcloud image and you’ll fine.

you can also link the container, so docker-compose will wait for the database to come up.

and there are container to update container. :wink:
https://hub.docker.com/r/v2tec/watchtower
https://hub.docker.com/r/pyouroboros/ouroboros

1 Like

yes. just docker stop ... ; docker run ... just replace “…” with the correct parameter. :wink:

if you are looking for a docker gui: -> https://hub.docker.com/r/portainer/portainer

1 Like

Both hints worked perfectly on my test container. Now i need to think how i can migrate my productive container, so the data from the current volume /var/www/html can be ported to the new named volume. I guess i’ll have to use rsync or similar.

yes. just docker stop ... ; docker run ... just replace “…” with the correct parameter. :wink:

Would this work in my case? I guess not, because i need to copy the data first from the container/volume.

if you are looking for a docker gui: -> https://hub.docker.com/r/portainer/portainer

I tried it already and it looks good. But how is it beneficial compared to plain console commands. Maybe i’ll have to take a deeper look into the “stack” feature and if there is a docker-compose feature.

But nevertheless, thanks for the really good hints!

BR,

Michael

the files you need are installed automatically during the first launch of the image. if we are talking about the nextcloud php code and stuff just have it installed. but you must make sure it fits to your database schema.

what is the state of your current setup? hundreds of user, with thousand of files and contacts and dates in the calendar? then it’s worse to thing about a strategy to bring up things. if you are the only user and all your files are still available as backups. don’t care, install new.

just a fancy gui. but for beginners quite nice. let’s say it’s a SOHO solution.

it is docker-compose. or swarm.

it’s just me, the boy and two droids :laughing:. No seriously, i have only two users and i don’t think it’s going to be much more. I guess i’ll just reinstall. The only thing, that should be a problem is i guess the “appdata_*” folder in data. But that can be fixed with a simple copy.

I have a container instance running and I peek into it from time to time. Sometimes it’s easier to restart a container via gui.

Before i start doing things with swarm etc. I think i need to finish my docker course on udemy :slight_smile: