Installing Nextcloud using Docker-Compose

Hello :slight_smile:

currently my plan is to switch away from google drive and nextcloud seems to be by far the best option.
I wish to use Docker, to have it done in a way I can deploy it on machines without the hassle of setting everything up again (If I need to move or upgrade nextcloud in the future).

The base system I use is Ubuntu 20.04 LTS.

The whole thing shall run behind a reverse proxy, so I can use the “insecure” deployment.

Basically it can mainly be the the provided template:

I clone this into /opt/Nextcloud and create the directories “/data” and “/postgres_db_data”.
Also I modify the upstream within the “nginx.conf”. That’s basically it. (The reverse-proxy listens on port 81 → will be changed)

This is my docker-compose file:

version: '3.9'

services:
  app:
    image: nextcloud:fpm-alpine
    container_name: nextcloud-app
    restart: unless-stopped
    volumes:
      - nextcloud-volume:/var/www/html
      - /opt/Nextcloud/data:/var/www/html/data
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    networks:
      - nextcloud
    environment:
      - NEXTCLOUD_TRUSTED_DOMAINS='localhost'
      - NEXTCLOUD_ADMIN_USER=admin
      - NEXTCLOUD_ADMIN_PASSWORD=<password>
      - POSTGRES_HOST=nextcloud-postgres
      - REDIS_HOST=nextcloud-redis
    env_file:
      - db.env
    depends_on:
      - postgres_db
      - redis

  web:
    build: ./web
    container_name: nextcloud-web
    restart: unless-stopped
    ports:
      - 127.0.0.1:81:80
    volumes:
      - nextcloud-volume:/var/www/html:ro
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    networks:
      - nextcloud
    depends_on:
      - app
      - cron
      - postgres_db

  cron:
    image: nextcloud:fpm-alpine
    container_name: nextcloud-cron
    restart: unless-stopped
    volumes:
      - nextcloud-volume:/var/www/html
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    networks:
      - nextcloud
    entrypoint: /cron.sh
    depends_on:
      - postgres_db
      - redis

  postgres_db:
    image: postgres:alpine
    container_name: nextcloud-postgres
    restart: unless-stopped
    volumes:
      - nextcloud-volume:/var/www/html
      - /opt/Nextcloud/postgres_db_data:/var/lib/postgresql/data
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
    networks:
      - nextcloud
    env_file:
      - db.env

  redis:
    image: redis:alpine
    container_name: nextcloud-redis
    networks:
      - nextcloud
    restart: unless-stopped

  collabora:
    image: collabora/code
    container_name: nextcloud-collabora
    restart: unless-stopped
    networks:
      - nextcloud
    ports:
      - 9980:9980
    environment:
      - domain=nextcloud.example.url
      - VIRTUAL_HOST=office.example.url
      - VIRTUAL_PORT=9980
      - VIRTUAL_PROTO=https
      - dictionaries='de_DE en_GB en_US nl_NL'
      - extra_params='--o:ssl.enable=false'
    cap_add:
      - MKNOD
    depends_on:
      - app
    tty: true

  coturn:
    image: instrumentisto/coturn
    container_name: nextcloud-coturn
    restart: unless-stopped
    ports:
      - 3478:3478/tcp
      - 3478:3478/udp
    networks:
      - nextcloud
    command:
      - -n
      - --log-file=stdout
      - --min-port=49160
      - --max-port=49200
      - --realm=https://nextcloud.example.url
      - --use-auth-secret
      - --static-auth-secret=<password>
    depends_on:
      - app

volumes:
  nextcloud-volume:

networks:
  nextcloud:

The plan was, that I just execute that and have a running Nextcloud instance.
But I can’t get it to work. All I get in the postgres logs is:

ERROR: relation “oc_migrations” already exists
STATEMENT: CREATE TABLE oc_migrations (app VARCHAR(255) NOT NULL, version VARCHAR(255) NOT NULL, PRIMARY KEY(app, version))

The Webinterface shows the same:
image

With a little searching I found:

He mentions the postgres db gets “killed” before the database gets first initialized.
In fact I tried to start the containers in a lot of different orders. But it makes no difference.

Have you guys any clue as what to try next? All ideas are very appreciated.

Thank you guys!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.