Set Up Nextcloud Using Docker




When it comes to cloud storage data, most users and companies use google drive platform. It is a good place to save your files into an online storage and therefore be able to reach your files from anywhere.

Of course, even google needs to sustain its services, so some restrictions like a limited cloud space are common. When you require more practical use in your business you will reach the point of having two options. To start paying the provider for their service or to try to implement your own way. One of the possible solutions for small or medium companies is to start using Nextcloud. Nextcloud is a free service which consists of many modules. The environment is very similar to Google’s so the majority of its users will already be able to use it.

Nextcloud Docker

One of the easiest ways to implement your own Nextcloud instance is to use Docker. Docker is a platform for sysadmins and developers to work with applications. The true power of docker is in containers. Deploy applications within containers is very accessible.

Containerization strong sites:

  • Flex: Any applications can be containerized.
  • Light: Not memory-intensive for virtualization
  • Agile: No need to pause or reboot, Deploy and upgrade online immediately.
  • Mobile: Build and deploy with no limitations locally or remotely.
  • Repeatable: automatically distribute replicas.

The article contains Docker installation by using repository on Ubuntu. You can easily achieve this using this series of commands:

sudo apt-get update
sudo apt-get install \
  apt-transport-https \
  ca-certificates \
  curl \
  gnupg-agent \
  software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
  "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Provided commands update the apt package index. Install packages to allow apt to use a repository over HTTPS. Add Docker’s official GPG key and download the latest version. A small tip; use systemctl linux service to have docker always running.

sudo systemctl enable docker

After the installation, verify that Docker is working by running your first command.

sudo docker run hello-world

docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest: sha256:ca0eeb6fb05351dfc8759c20733c91def84cb8007aa89a5bf606bc8b315b9fc7
Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.

So, Docker is up and running. There is one prerequisite necessary to have Nextcloud prepared for installation. You will need to have one of the database systems installed. Docker handles this very effectively. In this case, we install PostgreSQL.

docker run --name nextcloud-postgres -e POSTGRES_PASSWORD=mypassword -d postgres

root@workstation:/home/user/Desktop# docker run --name nextcloud-postgres -e
POSTGRES_PASSWORD=mypassword -d postgres
Unable to find image 'postgres:latest' locally
latest: Pulling from library/postgres
0a4690c5d889: Already exists
723861599717: Pull complete
db019468bdf4: Pull complete
91cb81a60371: Pull complete
a2a4ab07588d: Pull complete
Digest: sha256:68b49a280d2fbe9330c0031970ebb72015e1272dfa25f0ed7557514f9e5ad7b7
Status: Downloaded newer image for postgres:latest
9744f931bab7eaa56c312a207e3376a2b14098add4c971330d157402a5d0725

Remember the name of the database nextcloud-postgres and the password mypassword. You will need this later when you get into the Nextcloud setup page. Finally, everything is ready to install the Nextcloud application. Run the command.

docker run -d -p 8080:80 nextcloud

docker run -d -p 8080:80 nextcloud
Unable to find image 'nextcloud:latest' locally
latest: Pulling from library/nextcloud
0a4690c5d889: Pull complete
b07fddb037ca: Pull complete
7b3b87d31c03: Pull complete
540f9427ea56: Pull complete
Digest: sha256:5b3259052d851dac2b2d3ea0a104999a9fd392cf0c05dfaeaa5c600aefd8896e
Status: Downloaded newer image for nextcloud:latest
789731fa769676c7be67269a2d3c81c1f99c7a3945071a1ba2d4636356b1c7df

Number 8080 means which port should be used for the outside docker application. The second is the inside number of the port which uses Docker to run applications. The important part of all applications is to have setup persistent data because, otherwise, the progress would not be saved. In this case, you need to have persistent data for both SQL and Nextcloud.

docker run -d \
  -v nextcloud:/var/www/html \
  -v apps:/var/www/html/custom_apps \
  -v config:/var/www/html/config \
  -v data:/var/www/html/data \
  nextcloud
docker run -d \
  -v db:/var/lib/postgresql/data \
  Postgres

If you are running your Nextcloud installation locally, enter 127.0.0.1:8080 into your browser. You should be able to see the setup page.

  • Create and admin account:
    • Login - Nickname
    • Password – At least 8 characters
  • Storage & database:
    • Data folder - /var/www/nextcloud/data
    • Database username - postgres
    • Database password - mypassword
    • Database name – nextcloud-postgres
    • Database connection location – 127.0.01:5432

To sum up Nextcloud using Docker, it is good to say that one of the biggest advantages to Docker is the repeatable development, build, test, and production environments. Standardizing service infrastructure across the entire pipeline allows creating a huge infrastructure and saves a significant amount of time. Nextcloud is just one of many functioning cases you can achieve by using Docker-architecture.

Standa

DevOps Engineer

Do you have any questions or comments? Contact Us