# Installing Nextcloud using Docker-Compose

**URL:** <https://help.nextcloud.com/t/installing-nextcloud-using-docker-compose/126860>\
**Category:** ℹ️ Support\
**Tags:** postgresql, docker\
**Created:** [November 7, 2021, 11:15am UTC](https://help.nextcloud.com/t/installing-nextcloud-using-docker-compose/126860 "2021-11-07T11:15:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![courgette](https://help.nextcloud.com/user_avatar/help.nextcloud.com/courgette/32/41207_2.png) [@courgette](https://help.nextcloud.com/u/courgette)\
**Post date:** [November 7, 2021, 11:15am UTC](https://help.nextcloud.com/t/installing-nextcloud-using-docker-compose/126860/1 "2021-11-07T11:15:13Z")

</div>

Hello 🙂

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:

> **[docker/.examples/docker-compose/insecure/postgres/fpm at master ·...](https://github.com/nextcloud/docker/tree/master/.examples/docker-compose/insecure/postgres/fpm)**
>
> ⛴ Docker image of Nextcloud. Contribute to nextcloud/docker development by creating an account on GitHub.

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:

```auto
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](https://help.nextcloud.com/uploads/default/original/3X/9/1/91eb3b66e5b01797d98b9d8ac54bc869362501fc.png)

With a little searching I found:

> <https://github.com/nextcloud/docker/issues/1529>
>
> I'm running the \`nextcloud:21.0.3-apache\` image and sometimes when I re-create t…he container it just fails to start:
> \`\`\`
> Previous: PDOException: SQLSTATE\[42P07\]: Duplicate table: 7 ERROR: relation "oc\_migrations" already exists
> Trace: #0 /var/www/html/3rdparty/doctrine/dbal/src/Driver/PDO/Connection.php(82): PDO-\>query('CREATE TABLE oc...')
> \#1 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1035): Doctrine\\DBAL\\Driver\\PDO\\Connection-\>query('CREATE TABLE oc...')
> \#2 /var/www/html/lib/private/DB/Connection.php(226): Doctrine\\DBAL\\Connection-\>executeQuery('CREATE TABLE oc...', Array, Array, NULL)
> \#3 /var/www/html/3rdparty/doctrine/dbal/src/Connection.php(1757): OC\\DB\\Connection-\>executeQuery('CREATE TABLE oc...')
> \#4 /var/www/html/lib/private/DB/Migrator.php(256): Doctrine\\DBAL\\Connection-\>query('CREATE TABLE oc...')
> \#5 /var/www/html/lib/private/DB/Migrator.php(90): OC\\DB\\Migrator-\>applySchema(Object(Doctrine\\DBAL\\Schema\\Schema))
> \#6 /var/www/html/lib/private/DB/Connection.php(524): OC\\DB\\Migrator-\>migrate(Object(Doctrine\\DBAL\\Schema\\Schema))
> \#7 /var/www/html/lib/private/DB/MigrationService.php(178): OC\\DB\\Connection-\>migrateToSchema(Object(Doctrine\\DBAL\\Schema\\Schema))
> \#8 /var/www/html/lib/private/DB/MigrationService.php(192): OC\\DB\\MigrationService-\>createMigrationTable()
> \#9 /var/www/html/lib/private/DB/MigrationService.php(265): OC\\DB\\MigrationService-\>getMigratedVersions()
> \#10 /var/www/html/lib/private/DB/MigrationService.php(443): OC\\DB\\MigrationService-\>getMigrationsToExecute('latest')
> \#11 /var/www/html/lib/private/DB/MigrationService.php(418): OC\\DB\\MigrationService-\>migrateSchemaOnly('latest')
> \#12 /var/www/html/lib/private/Setup/AbstractDatabase.php(154): OC\\DB\\MigrationService-\>migrate('latest', true)
> \#13 /var/www/html/lib/private/Setup.php(378): OC\\Setup\\AbstractDatabase-\>runMigrations()
> \#14 /var/www/html/core/Command/Maintenance/Install.php(108): OC\\Setup-\>install(Array)
> \#15 /var/www/html/3rdparty/symfony/console/Command/Command.php(255): OC\\Core\\Command\\Maintenance\\Install-\>execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
> \#16 /var/www/html/3rdparty/symfony/console/Application.php(1009): Symfony\\Component\\Console\\Command\\Command-\>run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
> \#17 /var/www/html/3rdparty/symfony/console/Application.php(273): Symfony\\Component\\Console\\Application-\>doRunCommand(Object(OC\\Core\\Command\\Maintenance\\Install), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
> \#18 /var/www/html/3rdparty/symfony/console/Application.php(149): Symfony\\Component\\Console\\Application-\>doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
> \#19 /var/www/html/lib/private/Console/Application.php(215): Symfony\\Component\\Console\\Application-\>run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
> \#20 /var/www/html/console.php(100): OC\\Console\\Application-\>run()
> \#21 /var/www/html/occ(11): require\_once('/var/www/html/c...')
> \#22 {main}
> retrying install...
> \`\`\`
> And it's acting as if it's not configured at all and it's it's first startup, which it isn't:
> 
> !\[image\](https://user-images.githubusercontent.com/2212681/124582592-6ea62980-de52-11eb-9daf-b97803791f3b.png)
> 
> No idea what I'm supposed to do with this. I haven't touched the database, I just re-created the container...

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!

---

<div class="post-metadata">

**Author:** ![system](https://help.nextcloud.com/user_avatar/help.nextcloud.com/system/32/29333_2.png) [@system](https://help.nextcloud.com/u/system)\
**Post date:** [September 23, 2024, 4:22pm UTC](https://help.nextcloud.com/t/installing-nextcloud-using-docker-compose/126860/2 "2024-09-23T16:22:06Z")

</div>

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