I don’t have to say that Google sucks. Some of there services are great, and trust me, I know. I’ve been a life long Google user for years and still to this day I at least use one or two Google services in my life. But the implications that come with your privacy and the right to your data and what you can do with it are limiting. For the last two years I’ve been working to move away from the Google eco-system and finding FOSS and self-hosted alternatives that rock!
One such alternative is Nextcloud! I’ve been using Nextcloud for about a year now and it’s now something I cannot live without. It helps me sync all of my important documents, keep track of my tasks, schedule my life with the calendar, and so much more!
In this article, I’m going to show you how I’ve created a simple Nextcloud server you can setup anywhere with the power of docker and docker-compose. There are many ways to install Nextcloud to a server or a computer, but I find that docker and docker-compose is the easist as well the most flexible. especially with solutions such as Unraid and TrueNAS being available and supporting docker.
Before we get started, there’s a few things that you’ll need to setup before getting started. You’ll need to install docker and docker-compose. You’ll also need to create a dockerhub account and use the docker login command so you can pull images from dockerhub. Each machine’s setup for these is slightly different, but you can easily find tutorials online for installing and setting up docker.
With all that being said and with docker installed and setup, let’s get started creating our first Nextcloud server. Let’s start by creating a project folder and adding the files we’ll need:
mkdir -p my-nextcloud-server/docker/{mariadb,redis,nextcloud,nginx}
cd my-nextcloud-server
touch docker-compose.yml .env docker/{mariadb,redis,nextcloud,nginx}/Dockerfile
You should now have a project folder that looks like this:
.
├── docker
│ ├── mariadb
│ │ └── Dockerfile
│ ├── nextcloud
│ │ └── Dockerfile
│ ├── nginx
│ │ └── Dockerfile
│ └── redis
│ └── Dockerfile
├── docker-compose.yml
└── .env
Amazing! This will give us flexability to build out our own containers too! let’s start by adding our base images to all of our Dockerfiles:
docker/mariadb/Dockerfile
FROM mariadb/server:latest
docker/nextcloud/Dockerfile
FROM nextcloud:fpm-alpine
docker/nginx/Dockerfile
FROM nginx:alpine
RUN apk add wget
WORKDIR /etc/nginx/
RUN wget -O nginx.conf -L https://raw.githubusercontent.com/nextcloud/docker/master/.examples/docker-compose/insecure/mariadb/fpm/web/nginx.conf
docker/redis/Dockerfile
FROM redis:alpine
Now let’s setup a few enviorment variables for our docker-compose file to use:
.env
MYSQL_ROOT_PASSWORD = iamgroot
MYSQL_DATABASE = nextcloud
MYSQL_USER = nextcloud
MYSQL_PASSWORD = password
NEXTCLOUD_ADMIN_USER = jesse
NEXTCLOUD_ADMIN_PASSWORD = password
keep in mind, docker-secrets exist and should be used in a production enviorment. We wont cover those here but you can easily read up online on how to use them. Now with that in mind, let’s start on the main star of the show, the docker-compose file:
docker-compose.yml
version: '3'
volumes:
nextcloud:
mariadb:
services:
mariadb:
build: docker/mariadb
container_name: mariadb
restart: unless-stopped
volumes:
- mariadb:/var/lib/mysql
environment:
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
redis:
build: docker/redis
container_name: redis
restart: unless-stopped
app:
build: docker/nextcloud
container_name: app
restart: unless-stopped
depends_on:
- mariadb
- redis
volumes:
- nextcloud:/var/www/html
environment:
REDIS_HOST: redis
MYSQL_HOST: db
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
NEXTCLOUD_ADMIN_USER: ${NEXTCLOUD_ADMIN_USER}
NEXTCLOUD_ADMIN_PASSWORD: ${NEXTCLOUD_ADMIN_PASSWORD}
web:
build: docker/nginx
container_name: web
restart: unless-stopped
ports:
- 8080:80
depends_on:
- app
volumes:
- nextcloud:/var/www/html:ro
cron:
build: docker/nextcloud
container_name: cron
restart: unless-stopped
volumes:
- nextcloud:/var/www/html
entrypoint: /cron.sh
depends_on:
- mariadb
- redis
you should now be able to start up the nextcloud server using the docker-compose command:
docker-compose up
keep in mind, this is meant to be put behind a reverse-proxy of some sort but is a great starting point for getting started. You can read more about the Nextcloud image here and for other examples for a more secure connection here.
Stay tuned for more content about nextcloud and google alternatives!