Step 6: Configure Nextcloud using Docker Compose

Previously, we configured Nextcloud without any containers. This is bad news. All of our data will be deleted if we remove the container. Also, how do we back up our GBs worth of stored media files? There is no easy way to get this data out of the container.

Task: Your task is to apply what you learned about docker-compose.

Note

Stop and remove the current Nextcloud container before continuing

Initial Configuration

Use the instructions from Nextcloud docker-compose git page.

  1. Choose a base version: Apache or FPM

  2. Choose strong keys from randomkeygen.com for

    • MYSQL_ROOT_PASSWORD=

    • MYSQL_PASSWORD=

  3. Use port 20850:80

  4. Configure the volumes

    1. Configure all volume data so that they reside in the project directory. Use ./

    2. You do not need to configure named volumes

    root@vps298933:~/nextcloud-docker# docker ps
    CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                     NAMES
    76cbf38e5975        nextcloud            "/entrypoint.sh apac…"   5 minutes ago       Up 5 minutes        0.0.0.0:20850->80/tcp     nextclouddocker_app_1
    2906aaa944f5        mariadb              "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        3306/tcp                  nextclouddocker_db_1
    c60b6e70e4a9        wordpress:latest     "docker-entrypoint.s…"   2 hours ago         Up 2 hours          0.0.0.0:20851->80/tcp     wordpressdocker_wordpress_1
    386e4587b991        mariadb              "docker-entrypoint.s…"   2 hours ago         Up 2 hours          3306/tcp                  wordpressdocker_db_1
    913ff74dd94c        redis                "docker-entrypoint.s…"   2 hours ago         Up 2 hours          6379/tcp                  wordpressdocker_redis_1
    root@vps298933:~/nextcloud-docker#
    root@vps298933:~/nextcloud-docker# ls -lh
    total 12K
    drwxr-xr-x  5      999 root 4.0K Mar 30 15:14 db
    -rw-r--r--  1 root     root  657 Mar 30 15:13 docker-compose.yml
    drwxr-xr-x 15 www-data root 4.0K Mar 30 14:55 nextcloud
    root@vps298933:~/nextcloud-docker# ls -lh nextcloud/
    total 148K
    drwxr-xr-x 32 www-data root 4.0K Mar 30 14:54 3rdparty
    drwxr-xr-x 38 www-data root 4.0K Mar 30 14:55 apps
    -rw-r--r--  1 www-data root  12K Mar 30 14:54 AUTHORS
    drwxr-xr-x  2 www-data root 4.0K Mar 30 14:59 config
    -rw-r--r--  1 www-data root 3.6K Mar 30 14:54 console.php
    -rw-r--r--  1 www-data root  34K Mar 30 14:54 COPYING
    drwxr-xr-x 18 www-data root 4.0K Mar 30 14:55 core
    -rw-r--r--  1 www-data root 4.9K Mar 30 14:54 cron.php
    drwxr-xr-x  2 www-data root 4.0K Mar 30 14:55 custom_apps
    drwxrwx---  5 www-data root 4.0K Mar 30 15:01 data
    -rw-r--r--  1 www-data root  156 Mar 30 14:54 index.html
    
  5. Test the connection using curl --head localhost:20850

  6. Verify that you can access the site using the web browser (don’t log in yet)

  7. If you didn’t configure an Nginx site and install an SSL during the last lab, do it now.

Using the Nextcloud Web Configuration

Warning

Don’t continue unless you have enabled SSL for your Nextcloud site. You do not want to expose the login information.

  1. Navigate to your Nextcloud instance: cloud.example.com

  2. Enter an admin username and strong password

  3. Click on Storage & database

  4. Select MySQL/MariaDB

    ../../_images/nextcloud1.png
  5. Enter the information from your docker-compose.yml file

    • Database user: Value from MYSQL_USER

    • Database password: Value from MYSQL_PASSWORD

    • Database name: Value from MYSQL_DATABASE

    • Database host: The name of the database service in docker-compose.yml.

      • The default value is db

  6. Wait 2-3 minutes while your server configures Nextcloud

    ../../_images/nextcloud2.png

Optional Nextcloud Configuration

Nextcloud has options to use Redis. You now know how to configure it!

  1. You need to create a new Redis service in docker-compose.yml

  2. Add an environment variable to the app section

    REDIS_HOST=

    • Enter the name of the Redis service in your docker-compose file.

  3. Verify the service is active using redis-cli MONITOR

    root@vps298933:~/nextcloud-docker# docker ps
    CONTAINER ID        IMAGE                COMMAND                  CREATED             STATUS              PORTS                       NAMES
    76cbf38e5975        nextcloud            "/entrypoint.sh apac…"   5 minutes ago       Up 5 minutes        0.0.0.0:20850->80/tcp       nextclouddocker_app_1
    2906aaa944f5        mariadb              "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        3306/tcp                    nextclouddocker_db_1
    8f5b05b6c627        redis                "docker-entrypoint.s…"   5 minutes ago       Up 5 minutes        6379/tcp                    nextclouddocker_redis_1
    c60b6e70e4a9        wordpress:latest     "docker-entrypoint.s…"   2 hours ago         Up 2 hours          0.0.0.0:20851->80/tcp       wordpressdocker_wordpress_1
    386e4587b991        mariadb              "docker-entrypoint.s…"   2 hours ago         Up 2 hours          3306/tcp                    wordpressdocker_db_1
    913ff74dd94c        redis                "docker-entrypoint.s…"   2 hours ago         Up 2 hours          6379/tcp                    wordpressdocker_redis_1
    
    root@vps298933:~/nextcloud-docker# redis-cli -h 172.20.0.2 ping
    PONG
    root@vps298933:~/nextcloud-docker# redis-cli MONITOR
    root@vps298933:~/nextcloud-docker#
    Could not connect to Redis at 127.0.0.1:6379: Connection refused
    root@vps298933:~/nextcloud-docker# redis-cli -h 172.20.0.2 MONITOR
    OK
    1553938068.184906 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-core-actions/delete.svg"
    1553938068.185886 [0 172.20.0.4:56244] "EXISTS" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-core-actions/delete.svg"
    1553938068.188271 [0 172.20.0.4:56244] "SET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-core-actions/delete.svg" "\"\\/core\\/img\\/actions\\/delete.svg\""
    1553938068.194019 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-settings-help.svg"
    1553938068.194443 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-settings-apps.svg"
    1553938068.194782 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-settings-admin.svg"
    1553938068.200861 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-core-actions/logout.svg"
    1553938068.201404 [0 172.20.0.4:56244] "GET" "a33118d6be8e2ada2b6852d13d2f6958/imagePath-d15c90b58d69c88bb4238831e8768cf4-settings-users.svg"
    .
    .
    .
    

Congratulations! You just installed Nextcloud using three containers with minimal help. You know how the knowledge and experience to install many applications that are available through Docker Compose.