Recently, I have been feeling a bit limited with the online storage I’ve been using. My photos and videos suffer a bit of quality degradation. I am limited in the amount I can store, and if the provider ever decides to shut itself down, all the data I have stored will just vanish. I mean, I am using Google Drive like most of us, I am assuming, and I don’t really expect them to just shut down one of their most popular services. While the longevity of my data may not be in question, the other issues give me the feeling that my data isn’t really mine, which left a bad taste in my mouth. So I asked a question: How can I create my own cloud storage that functions like Google Drive but under my complete control?
The solution I found is Nextcloud, a robust open-source platform that can be deployed using Docker. This is perfect for my use case since I’ll run this in a Docker container locally and connect to it remotely from different clients.
Setup Docker Compose
So lets setup this Docker Compose file so we can get up and running. Now, Nextcloud is compatible with two kinds of databases, MySQL and Postgres. I will show the configuration for Postgres, if you would like to see one for MySQL I have a repo setup that has a compose file for either.
services: db: image: postgres restart: always volumes: - db:/var/lib/postgresql/data environment: - POSTGRES_DB=${POSTGRES_DB} - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} app: image: nextcloud restart: always ports: - 8080:80 - 8443:443 links: - db volumes: - nextcloud:/var/www/html environment: - POSTGRES_HOST=db - POSTGRES_DB=${POSTGRES_DB} - POSTGRES_USER=${POSTGRES_USER} - POSTGRES_PASSWORD=${POSTGRES_PASSWORD} volumes: db: nextcloud:
From there all you need to do is run `docker-compose up -d` both your db and nextcloud containers should be spun up and you should be able to access next cloud by going to localhost:8080 where you will run your initial config.
Initial Configuration of Nextcloud
On first launch, you’ll see a prompt to create a username and password combo for the admin login. Make sure to remember what you set as you will need it later. After that it will ask if you want to install any of the other apps in Nextcloud’s app suite and you can skip this for now. If you decide you want to install these later you can. And there you go you now have your own cloud storage application that you can add or delete files to. But you may have guessed this is still isolated to the machine we are running the Docker container on. Not very useful as a “cloud” storage solution if we can’t access it from other machines while not on the same network.
Setup Tailscale
That is where tailscale comes in. Tailscale is another open-source software that allows you to create your own VPN. Just as with Nextcloud, there are paid versions, but you get most of the functionality you need with the free version. By utilizing this VPN, we will be able to connect to and access our Nextcloud storage from anywhere.
To start download Tailscale on the same machine that you are running your Docker containers on. When you start the app, you will need to make an account and log in. After successfully logging in, you should see the machines in your network. Currently, it should be just one. Next, you will need to make sure that MagicDNS is enabled by navigating to the DNS tab and scrolling to near the bottom. After enabling MagicDNS go back to the Machines tab and get the DNS and IP address of the host machine from the addresses column. We will need both for the next step.
Also take this time to add the devices you want to have access to Nextcloud to your Tailscale network by downloading the application on each device and logging into Tailscale with the same login you created on the host machine. This will automatically add the current device to your network.
Add trusted Domains
With the DNS and ip address obtained earlier in a terminal window you will want to run the following command. `docker exec -u www-data <app-container-name> php /var/www/html/occ config:system:set trusted_domains <DOMAIN_INDEX> –value=<DNS/IPADDRESS>;`.
DOMAIN INDEX will be the index of the domain in the trusted domain list, and because 0 is already taken by the local host, start from 1. DNS/IPADDRESS will be the DNS and or IP that you wish to add. You can only add one at a time.
If everything ran successfully, you can, using a device connected to your VPN, open a browser and navigate to `<DNS/IPADDRESS>:8080`. You’ll see the Nextcloud login screen. Congratulations! You have now created your own private cloud storage application — one only you can access.