Use a Block Storage Volume with Nextcloud

Updated by Linode Written by Jared Kobos

Contribute on GitHub

Report an Issue | View File | Edit File

What is Nextcloud?

Nextcloud is a cloud storage platform that allows you to store and access your files from any device. This guide shows how to attach a Block Storage Volume to a Linode in order to meet the demands of a large file library.

Before You Begin

  • You will need root access to your Linode, or a user account with sudo privilege.
  • Update your system.

Install Docker and Docker Compose

Docker

These steps install Docker Community Edition (CE) using the official Ubuntu repositories. To install on another distribution, or to install on Mac or Windows, see the official installation page.

  1. Remove any older installations of Docker that may be on your system:

    sudo apt remove docker docker-engine docker.io
    
  2. Make sure you have the necessary packages to allow the use of Docker’s repository:

    sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg
    
  3. Add Docker’s GPG key:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  4. Verify the fingerprint of the GPG key:

    sudo apt-key fingerprint 0EBFCD88
    

    You should see output similar to the following:

      
    pub   rsa4096 2017-02-22 [SCEA]
          9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
    uid           [ unknown] Docker Release (CE deb) 
    sub   rsa4096 2017-02-22 [S]
    
    
  5. Add the stable Docker repository:

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    
    Note

    For Ubuntu 19.04, if you get an E: Package 'docker-ce' has no installation candidate error, this is because the stable version of docker is not yet available. Therefore, you will need to use the edge / test repository.

    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable edge test"
    
  6. Update your package index and install Docker CE:

    sudo apt update
    sudo apt install docker-ce
    
  7. Add your limited Linux user account to the docker group:

    sudo usermod -aG docker $USER
    
    Note
    After entering the usermod command, you will need to close your SSH session and open a new one for this change to take effect.
  8. Check that the installation was successful by running the built-in “Hello World” program:

    docker run hello-world
    

Docker Compose

  1. Download the latest version of Docker Compose. Check the releases page and replace 1.25.4 in the command below with the version tagged as Latest release:

    sudo curl -L https://github.com/docker/compose/releases/download/1.25.4/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
    
  2. Set file permissions:

    sudo chmod +x /usr/local/bin/docker-compose
    

Attach a Block Storage Volume

  1. Create a Block Storage Volume and attach it to your Linode. See How to Add a Block Storage Volume to a Linode for instructions on how to do this from the Linode Manager.

    • You can also use the Linode CLI to create a new Volume. The command below creates a 20GB Volume with the label nextcloud attached to a Linode labeled nextcloud-linode. Adjust the command as needed:

      linode-cli volume create nextcloud -l nextcloud-linode -s 20
      
  2. Create a filesystem on the Block Storage Volume, then create a mount point per the instructions from the Linode Manager:

    Mount Block Storage Volume

  3. Check available disk space. Notice that there is some overhead with the Volume due to the file system:

    df -BG
    
      
    Filesystem     1G-blocks  Used Available Use% Mounted on
    /dev/root            20G    2G       18G   6% /
    devtmpfs              1G    0G        1G   0% /dev
    tmpfs                 1G    0G        1G   0% /dev/shm
    tmpfs                 1G    1G        1G   2% /run
    tmpfs                 1G    0G        1G   0% /run/lock
    tmpfs                 1G    0G        1G   0% /sys/fs/cgroup
    tmpfs                 1G    0G        1G   0% /run/user/1000
    /dev/sdc             20G    1G       19G   1% /mnt/nextcloud
    
    
  4. Change the ownership of the mount point:

    sudo chown username:username /mnt/nextcloud/
    

Configure Nextcloud with Docker Compose

Nextcloud provides an official docker-compose.yml file for persisting data to a database when running the Nextcloud container. You can edit this file to bind the data volumes to your Block Storage Volume’s mount point.

  1. Create a directory for Nextcloud:

    mkdir ~/nextcloud && cd ~/nextcloud
    
  2. In a text editor, create docker-compose.yml and add the following content. Add an appropriate password for MariaDB:

    ~/nextcloud/docker-compose.yml
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    version: '2'
    
    volumes:
      nextcloud:
      db:
    
    services:
      db:
        image: mariadb
        restart: always
        volumes:
          - /mnt/nextcloud/:/var/lib/mysql
        environment:
          - MYSQL_ROOT_PASSWORD=
          - MYSQL_PASSWORD=
          - MYSQL_DATABASE=nextcloud
          - MYSQL_USER=nextcloud
    
      app:
        image: nextcloud
        ports:
          - 8080:80
        links:
          - db
        volumes:
          - /mnt/nextcloud/data:/var/www/html
        restart: always
  3. Launch the Docker Compose configuration:

    docker-compose up -d
    

    Nextcloud should be available at port 8080 on your Linode’s public IP address.

  4. When creating an admin account, open the Storage & database drop-down menu, fill in the information as shown below, and enter the MariaDB password you used in the docker-compose file:

    Nextcloud database connection

Caution
The setup provided by Nextcloud does not include any SSL encryption. To secure your data and communications, the Nextcloud service should be placed behind a reverse proxy. A Docker Compose file using an NGINX reverse proxy and Let’s Encrypt is also available.

Upload Data

  1. After you have created an admin account, the Nextcloud dashboard will be displayed. Click on the + icon in the upper left and select Upload file. For demonstration purposes, choose a large file (an Ubuntu .iso file was used to generate the output below).

    Nextcloud Upload File

  2. After the file has uploaded successfully, return to the terminal and check to see your available space:

    df -BG
    
      
    Filesystem     1G-blocks  Used Available Use% Mounted on
    /dev/root            20G    2G       17G  11% /
    devtmpfs              1G    0G        1G   0% /dev
    tmpfs                 1G    0G        1G   0% /dev/shm
    tmpfs                 1G    1G        1G   2% /run
    tmpfs                 1G    0G        1G   0% /run/lock
    tmpfs                 1G    0G        1G   0% /sys/fs/cgroup
    /dev/sdc             20G    2G       17G  11% /mnt/nextcloud
    tmpfs                 1G    0G        1G   0% /run/user/1000
    
    

    The output should show that the file has been stored in /mnt/nextcloud, which is the mount point for the Block Storage Volume.

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Join our Community

Find answers, ask questions, and help others.

This guide is published under a CC BY-ND 4.0 license.