Back to blog
Oct 04, 2024
3 min read

Installing Nextcloud Using Docker Compose

Follow this step-by-step guide to install Nextcloud using Docker Compose for easy and efficient cloud storage management.

Nextcloud is a powerful open-source software suite that provides file hosting and collaboration capabilities. Installing Nextcloud with Docker Compose simplifies the setup process and allows you to manage your Nextcloud instance easily. This guide will walk you through the steps to install Nextcloud using Docker Compose on a Linux system.

Prerequisites

Before you begin, ensure you have the following:

  • A Linux server running Ubuntu 22.04.
  • Docker and Docker Compose installed. If you haven’t installed Docker and Docker Compose, refer to the Docker installation guide.

Step 1: Create a Directory for Nextcloud

  1. SSH into your server.

  2. Create a directory for the Nextcloud project:

    mkdir ~/nextcloud
    cd ~/nextcloud
    

Step 2: Create a Docker Compose File

Create a file named docker-compose.yml in the nextcloud directory:

nano docker-compose.yml

Add the following configuration to the file:

version: '3.8'

services:
  nextcloud:
    image: nextcloud
    ports:
      - 8080:80
    volumes:
      - nextcloud_data:/var/www/html
    environment:
      - MYSQL_PASSWORD=your_mysql_password
      - NEXTCLOUD_ADMIN_USER=admin
      - NEXTCLOUD_ADMIN_PASSWORD=your_admin_password
      - MYSQL_HOST=db
      - MYSQL_DATABASE=nextcloud
    depends_on:
      - db

  db:
    image: mysql:5.7
    volumes:
      - db_data:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=your_mysql_root_password
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
      - MYSQL_PASSWORD=your_mysql_password

volumes:
  nextcloud_data:
  db_data:

Replace the following placeholders with your desired values:

  • your_mysql_password: A strong password for the Nextcloud database.
  • your_admin_password: A strong password for the Nextcloud admin user.
  • your_mysql_root_password: A strong password for the MySQL root user.

Step 3: Start the Nextcloud Stack

Run the following command to start the Nextcloud and MySQL services:

docker-compose up -d

The -d flag runs the containers in detached mode. You can view the logs using:

docker-compose logs -f

Step 4: Access Nextcloud

Once the services are running, you can access Nextcloud in your web browser by navigating to:

http://your_server_ip:8080

Replace your_server_ip with your server’s IP address.

You should see the Nextcloud setup page. Follow the on-screen instructions to complete the installation.

Step 5: Configure Additional Settings (Optional)

  1. Data Encryption: Consider enabling data encryption in Nextcloud settings for added security.
  2. SSL Configuration: If you’re exposing your Nextcloud instance to the internet, it’s essential to set up SSL. You can use Let’s Encrypt for a free SSL certificate.
  3. Backups: Regularly back up your Nextcloud data and database to prevent data loss.

Step 6: Stopping and Restarting Nextcloud

To stop the Nextcloud services, run:

docker-compose down

To restart the services, use:

docker-compose up -d

Conclusion

You have successfully installed Nextcloud using Docker Compose. This setup allows you to manage your Nextcloud instance efficiently and provides a solid foundation for file hosting and collaboration. Make sure to explore Nextcloud’s features and customize it to fit your needs.