Deploying Nextcloud in Docker

Nextcloud is a cloud based workspace app, comparable to Google Drive or Onedrive. However, Nextcloud is opensource, so you’re free to host your own instance. You just need the compute and storage.

I host many of my apps on my personal home server using Docker. Here’s a quick guide on how to get Nextcloud up and running on your own server.

Docker Compose 

For this, you’re going to need docker and docker-compose packages installed. Use whichever package manager is appropriate for your distribution.

Creating a docker-compose file allows us to destroy a docker container, pull the latest image, and then redeploy. This is useful for updates, but fair warning, you must update one major version at a time

1. Create “docker-compose.yml”

touch docker-compose.yml

2. Save your MYSQL password and root passwords to .env, docker-compose will find them automatically.

echo "MYSQL_PASSWORD=your_msql_password 
MYSQL_ROOT_PASSWORD=your_root_password" > .env

3. Enter the following into your docker-compose.yml file

version: '2'

services:
 db:
   image: mariadb
   restart: always
   command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
   volumes:
     - db:/var/lib/mysql
   environment:
     - MYSQL_ROOT_PASSWORD={$MYSQL_ROOT_PASSWORD}
     - MYSQL_PASSWORD={$MYSQL_PASSWORD}
     - MYSQL_DATABASE=nextcloud
     - MYSQL_USER=nextcloud

 app:
   image: nextcloud
   restart: always
   ports:
     - 80:80
   links:
     - db
   volumes:
     - app:/var/www/html
   environment:
     - MYSQL_PASSWORD={$MYSQL_PASSWORD}
     - MYSQL_DATABASE=nextcloud
     - MYSQL_USER=nextcloud
     - MYSQL_HOST=db

volumes:
	db:
	app:

If port 80 is already in use, you can change the bind port to something else, like 8080:80

4. Get your docker images

docker-compose pull

5. Run Nextcloud

docker-compose up -d

Now you’ll be able to access the site. Head to http://localhost and you’ll be welcomed with the first time setup page. Create your admin account, and then you’re done.

Congrats, your own personal cloud storage provider!