title: Set up nextcloud with postgres both via docker
body: <p>I would like to set up nextcloud locally with postgres via docker. I am able to do so without attempting to use postgres (i.e. with default sqllite) but I run into problems when using postgres docker in conjunction with the nc image.</p>
  <p>My laptop is Ubuntu 18.04.</p>
  <p>Goal:
  I would like to have a containerized set up locally that I can easily (or at least somewhat easily) move to a cloud provider whenever I like. I'm setting up volumes for postgres as well as nc so that I can transfer everything to a remote as when I choose.</p>
  <p>Here's my repo which includes Dockerfile and docker-compose:</p>
  <p><strong>Dockerfile:</strong> (Note I add smbclient since I learned the hard way that I need this to install the app for external storage, which I'd like to use)</p>
  <pre><code>FROM nextcloud:production-apache
  RUN apt-get update &amp;&amp; apt-get install -y \
     smbclient
  </code></pre>
  <p><strong>My docker-compose file:</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>version: &quot;3.5&quot;
  services:
    nextcloud:
      build:
        context: .
        dockerfile: ./Dockerfile
      ports:
        - &quot;8080:80&quot;
      volumes:
        - $PROJECTS_DIR/Personal/mc1/nextcloud:/var/www/html
        - $PROJECTS_DIR/Personal/mc1/apps:/var/www/html/custom_apps
        - $PROJECTS_DIR/Personal/mc1/config:/var/www/html/config 
        - $PROJECTS_DIR/Personal/mc1/data:/var/www/html/data
      environment:
        - POSTGRES_HOST=nextcloud_db_1 # service name for postgres as assigned by Docker
        - POSTGRES_DB=nextcloud_db
        - POSTGRES_USER=postgres # will access postgres over 5432
        - POSTGRES_PASSWORD=testing123
      depends_on:
        - db
  
    db:
      image: postgres
      restart: always
      volumes:
        - ./postgres-data:/var/lib/postgresql/data
      environment:
        - POSTGRES_DB=nextcloud_db
        - POSTGRES_USER=postgres
        - POSTGRES_PASSWORD=testing123
  </code></pre>
  <p>I wasn't very sure how to set this up and borrowed from another post <a href="https://help.nextcloud.com/t/how-to-nextcloud-with-postgres-in-docker/80820" rel="nofollow noreferrer">here</a>.</p>
  <p>Outcome:</p>
  <p>With a terminal in the repo:</p>
  <pre><code>docker-compose build
  docker-compose up -d
  </code></pre>
  <p>I can then access nc at http://localhost:8080/index.php where I select 'postgres' and enter the postgres details from my docker-compose:
  <a href="https://i.stack.imgur.com/9NdZu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9NdZu.png" alt="enter image description here" /></a></p>
  <p>After entering all the details in the screenshot above, when I click 'finish  setup' I get this error screen:
  <a href="https://i.stack.imgur.com/DtnUk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DtnUk.png" alt="enter image description here" /></a></p>
  <p>I searched for a file called 'log' anywhere in the volumes and found data/nextcloud.log. Here's what it's showing:</p>
  <pre class="lang-json prettyprint-override"><code>{&quot;reqId&quot;:&quot;WqeSp92UPr935aMdZ0XY&quot;,&quot;level&quot;:2,&quot;time&quot;:&quot;2021-01-17T23:32:25+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;no app in context&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:&quot;Host localhost was not connected to because it violates local access rules&quot;,&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;&quot;}
  {&quot;reqId&quot;:&quot;WqeSp92UPr935aMdZ0XY&quot;,&quot;level&quot;:2,&quot;time&quot;:&quot;2021-01-17T23:32:25+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;no app in context&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:&quot;Host localhost was not connected to because it violates local access rules&quot;,&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;&quot;}
  {&quot;reqId&quot;:&quot;WqeSp92UPr935aMdZ0XY&quot;,&quot;level&quot;:3,&quot;time&quot;:&quot;2021-01-17T23:32:26+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;no app in context&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:{&quot;Exception&quot;:&quot;Doctrine\\DBAL\\DBALException&quot;,&quot;Message&quot;:&quot;Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not translate host name \&quot;nextcloud_db_1\&quot; to address: Temporary failure in name resolution&quot;,&quot;Code&quot;:0,&quot;Trace&quot;:[{&quot;file&quot;:&quot;/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php&quot;,&quot;line&quot;:428,&quot;function&quot;:&quot;connect&quot;,&quot;class&quot;:&quot;OC\\DB\\Connection&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php&quot;,&quot;line&quot;:388,&quot;function&quot;:&quot;getDatabasePlatformVersion&quot;,&quot;class&quot;:&quot;Doctrine\\DBAL\\Connection&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/3rdparty/doctrine/dbal/lib/Doctrine/DBAL/Connection.php&quot;,&quot;line&quot;:330,&quot;function&quot;:&quot;detectDatabasePlatform&quot;,&quot;class&quot;:&quot;Doctrine\\DBAL\\Connection&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/lib/private/DB/QueryBuilder/QueryBuilder.php&quot;,&quot;line&quot;:119,&quot;function&quot;:&quot;getDatabasePlatform&quot;,&quot;class&quot;:&quot;Doctrine\\DBAL\\Connection&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/lib/private/Setup/PostgreSQL.php&quot;,&quot;line&quot;:54,&quot;function&quot;:&quot;expr&quot;,&quot;class&quot;:&quot;OC\\DB\\QueryBuilder\\QueryBuilder&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/lib/private/Setup.php&quot;,&quot;line&quot;:359,&quot;function&quot;:&quot;setupDatabase&quot;,&quot;class&quot;:&quot;OC\\Setup\\PostgreSQL&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;rstudio&quot;]},{&quot;file&quot;:&quot;/var/www/html/core/Controller/SetupController.php&quot;,&quot;line&quot;:75,&quot;function&quot;:&quot;install&quot;,&quot;class&quot;:&quot;OC\\Setup&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;*** sensitive parameters replaced ***&quot;]},{&quot;file&quot;:&quot;/var/www/html/lib/base.php&quot;,&quot;line&quot;:946,&quot;function&quot;:&quot;run&quot;,&quot;class&quot;:&quot;OC\\Core\\Controller\\SetupController&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;*** sensitive parameters replaced ***&quot;]},{&quot;file&quot;:&quot;/var/www/html/index.php&quot;,&quot;line&quot;:37,&quot;function&quot;:&quot;handleRequest&quot;,&quot;class&quot;:&quot;OC&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[]}],&quot;File&quot;:&quot;/var/www/html/lib/private/DB/Connection.php&quot;,&quot;Line&quot;:72,&quot;CustomMessage&quot;:&quot;--&quot;},&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;20.0.4.0&quot;}
  {&quot;reqId&quot;:&quot;WqeSp92UPr935aMdZ0XY&quot;,&quot;level&quot;:2,&quot;time&quot;:&quot;2021-01-17T23:32:26+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;no app in context&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:&quot;Error trying to connect as \&quot;postgres\&quot;, assuming database is setup and tables need to be created&quot;,&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;20.0.4.0&quot;}
  {&quot;reqId&quot;:&quot;WqeSp92UPr935aMdZ0XY&quot;,&quot;level&quot;:3,&quot;time&quot;:&quot;2021-01-17T23:32:26+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;no app in context&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:{&quot;Exception&quot;:&quot;Doctrine\\DBAL\\DBALException&quot;,&quot;Message&quot;:&quot;Failed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not translate host name \&quot;nextcloud_db_1\&quot; to address: Temporary failure in name resolution&quot;,&quot;Code&quot;:0,&quot;Trace&quot;:[{&quot;file&quot;:&quot;/var/www/html/lib/private/Setup/PostgreSQL.php&quot;,&quot;line&quot;:98,&quot;function&quot;:&quot;connect&quot;,&quot;class&quot;:&quot;OC\\DB\\Connection&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/lib/private/Setup.php&quot;,&quot;line&quot;:359,&quot;function&quot;:&quot;setupDatabase&quot;,&quot;class&quot;:&quot;OC\\Setup\\PostgreSQL&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;rstudio&quot;]},{&quot;file&quot;:&quot;/var/www/html/core/Controller/SetupController.php&quot;,&quot;line&quot;:75,&quot;function&quot;:&quot;install&quot;,&quot;class&quot;:&quot;OC\\Setup&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;*** sensitive parameters replaced ***&quot;]},{&quot;file&quot;:&quot;/var/www/html/lib/base.php&quot;,&quot;line&quot;:946,&quot;function&quot;:&quot;run&quot;,&quot;class&quot;:&quot;OC\\Core\\Controller\\SetupController&quot;,&quot;type&quot;:&quot;-&gt;&quot;,&quot;args&quot;:[&quot;*** sensitive parameters replaced ***&quot;]},{&quot;file&quot;:&quot;/var/www/html/index.php&quot;,&quot;line&quot;:37,&quot;function&quot;:&quot;handleRequest&quot;,&quot;class&quot;:&quot;OC&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[]}],&quot;File&quot;:&quot;/var/www/html/lib/private/DB/Connection.php&quot;,&quot;Line&quot;:72,&quot;CustomMessage&quot;:&quot;--&quot;},&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;20.0.4.0&quot;}
  {&quot;reqId&quot;:&quot;webBnsoANvgRaansmKbZ&quot;,&quot;level&quot;:3,&quot;time&quot;:&quot;2021-01-17T23:32:41+00:00&quot;,&quot;remoteAddr&quot;:&quot;192.168.32.1&quot;,&quot;user&quot;:&quot;--&quot;,&quot;app&quot;:&quot;index&quot;,&quot;method&quot;:&quot;POST&quot;,&quot;url&quot;:&quot;/index.php&quot;,&quot;message&quot;:{&quot;Exception&quot;:&quot;OC\\DatabaseException&quot;,&quot;Message&quot;:&quot;An exception occurred while executing 'SHOW SERVER_VERSION':\n\nFailed to connect to the database: An exception occurred in driver: SQLSTATE[08006] [7] could not translate host name \&quot;nextcloud_db_1\&quot; to address: Temporary failure in name resolution&quot;,&quot;Code&quot;:0,&quot;Trace&quot;:[{&quot;file&quot;:&quot;/var/www/html/lib/private/legacy/OC_DB.php&quot;,&quot;line&quot;:143,&quot;function&quot;:&quot;prepare&quot;,&quot;class&quot;:&quot;OC_DB&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[&quot;SHOW SERVER_VERSION&quot;,null,null]},{&quot;file&quot;:&quot;/var/www/html/lib/private/legacy/OC_Util.php&quot;,&quot;line&quot;:984,&quot;function&quot;:&quot;executeAudited&quot;,&quot;class&quot;:&quot;OC_DB&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[{&quot;sql&quot;:&quot;SHOW SERVER_VERSION&quot;,&quot;limit&quot;:null,&quot;offset&quot;:null}]},{&quot;file&quot;:&quot;/var/www/html/lib/private/legacy/OC_Util.php&quot;,&quot;line&quot;:964,&quot;function&quot;:&quot;checkDatabaseVersion&quot;,&quot;class&quot;:&quot;OC_Util&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/lib/base.php&quot;,&quot;line&quot;:660,&quot;function&quot;:&quot;checkServer&quot;,&quot;class&quot;:&quot;OC_Util&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[{&quot;__class__&quot;:&quot;OC\\SystemConfig&quot;}]},{&quot;file&quot;:&quot;/var/www/html/lib/base.php&quot;,&quot;line&quot;:1091,&quot;function&quot;:&quot;init&quot;,&quot;class&quot;:&quot;OC&quot;,&quot;type&quot;:&quot;::&quot;,&quot;args&quot;:[]},{&quot;file&quot;:&quot;/var/www/html/index.php&quot;,&quot;line&quot;:35,&quot;args&quot;:[&quot;/var/www/html/lib/base.php&quot;],&quot;function&quot;:&quot;require_once&quot;}],&quot;File&quot;:&quot;/var/www/html/lib/private/legacy/OC_DB.php&quot;,&quot;Line&quot;:73,&quot;CustomMessage&quot;:&quot;--&quot;},&quot;userAgent&quot;:&quot;Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:84.0) Gecko/20100101 Firefox/84.0&quot;,&quot;version&quot;:&quot;20.0.4.0&quot;}
  </code></pre>
  <p>Is my set up sound or is this a bug? I'm not confident in my postgres addition in docker-compose or if I have done that correctly?</p>
  <p>How can I set up nextcloud locally with postgres using docker and volumes so that I can transfer my entire nextcloud set up from cloud provider to cloud provider as I choose?</p>