Install NextCloud with Docker Compose on Ubuntu 22.04

Install NextCloud dengan Docker Compose pada Ubuntu 22.04

  • nex.bikinin.website – 103.169.7.138
  • Update repository ubuntu dan install dependencies
root@ubuntu-2204:~# apt update && apt upgrade -y
root@ubuntu-2204:~# apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y

Install Docker CE

  • Tambahkan repository Docker official GPG key
root@ubuntu-2204:~# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • Set repository stable docker ce
root@ubuntu-2204:~# echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
  • Jika pada server terdapat docker versi lama, pastikan harus di hapus terlebih dahulu
root@ubuntu-2204:~#  apt remove docker docker-engine docker.io containerd runc
  • Install Docker CE versi terbaru
root@ubuntu-2204:~# apt update
root@ubuntu-2204:~# apt install docker-ce docker-ce-cli containerd.io -y
root@ubuntu-2204:~# reboot
  • Cek versi docker ce
root@ubuntu-2204:~# docker version
Client: Docker Engine - Community
 Version:           20.10.14
 API version:       1.41
 Go version:        go1.16.15
 Git commit:        a224086
 Built:             Thu Mar 24 01:47:47 2022
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.14
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.16.15
  Git commit:       87a90dc
  Built:            Thu Mar 24 01:45:38 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.5.11
  GitCommit:        3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc:
  Version:          1.0.3
  GitCommit:        v1.0.3-0-gf46b6ba
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Install Docker Compose

  • Versi terbaru docker compose bisa dilihat disini: https://github.com/docker/compose/releases
  • Install Docker Compose, ganti huruf v2.17.0 sesuai dengan versi yang ingin di install
root@ubuntu-2204:~# curl -L "https://github.com/docker/compose/releases/download/v2.17.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  • Tambahkan executable permission dan buat symbolic link ke file /usr/bin/docker-compose
root@ubuntu-2204:~# chmod +x /usr/local/bin/docker-compose
root@ubuntu-2204:~# ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
  • Cek versi Docker Compose
root@ubuntu-2204:~# docker-compose --version
Docker Compose version v2.17.0

Install NextCloud dengan Docker Compose

  • Buat directory nextcloud
root@ubuntu-2204:~# mkdir nextcloud && cd nextcloud
  • Buat file docker-compose.yml
root@ubuntu-2204:~/nextcloud# nano docker-compose.yml
version: '1.0'
services:
   sys-ops_nex_db:
     image: mariadb:10.6
     container_name: sys-ops_nex_db
     volumes:
       - sys-ops_nex_db_data:/var/lib/mysql
     restart: always
     environment:
       MYSQL_ROOT_PASSWORD: pass_root
       MYSQL_DATABASE: db_nex
       MYSQL_USER: user_nex
       MYSQL_PASSWORD: pass_nex
   sys-ops_nex_app:
     depends_on:
       - sys-ops_nex_db
     image: nextcloud:latest
     container_name: sys-ops_nex_app
     volumes:
       - sys-ops_nex_app_data:/var/www/html
     ports:
       - "81:80"
     restart: always
     environment:
       WORDPRESS_DB_HOST: db:3306
       WORDPRESS_DB_USER: user_nex
       WORDPRESS_DB_PASSWORD: pass_nex
       WORDPRESS_DB_NAME: db_nex
volumes:
    sys-ops_nex_db_data: {}
    sys-ops_nex_app_data: {}
  • Jalankan docker compose
root@ubuntu-2204:~/nextcloud# docker-compose up -d

[+] Running 33/33
 ⠿ sys-ops_nex_app Pulled                                                 87.0s
   ⠿ 09ba2f5755bc Pull complete                                           76.3s
   ⠿ e4dbf168d04b Pull complete                                           77.1s
   ⠿ 527dd53e608d Pull complete                                           77.6s
 ⠿ sys-ops_nex_db Pulled                                                  60.3s
   ⠿ 52b208fdad78 Pull complete                                           45.4s
   ⠿ 63854a3a9dec Pull complete                                           46.6s
   ⠿ f19cdb26b952 Pull complete                                           52.7s
[+] Running 5/5
 ⠿ Network nextcloud_default                Created                       0.5s
 ⠿ Volume "nextcloud_sys-ops_nex_app_data"  Created                       0.0s
 ⠿ Volume "nextcloud_sys-ops_nex_db_data"   Created                       0.0s
 ⠿ Container sys-ops_nex_db                 Started                       4.0s
 ⠿ Container sys-ops_nex_app                Started                       5.2s
  • Cek status container
root@ubuntu-2204:~/nextcloud# docker ps -a

CONTAINER ID   IMAGE              COMMAND                  CREATED          STATUS          PORTS                                   NAMES
c0fd3bbe6bd2   nextcloud:latest   "/entrypoint.sh apac…"   29 minutes ago   Up 29 minutes   0.0.0.0:81->80/tcp, :::81->80/tcp       sys-ops_nex_app
108c263ef4f5   mariadb:10.6       "docker-entrypoint.s…"   29 minutes ago   Up 29 minutes   3306/tcp                                sys-ops_nex_db

Setting Apache Reverse Proxy

  • script apache reverse proxy
root@ubuntu-2204:~/nextcloud# nano /etc/apache2/sites-available/nex.bikinin.website.conf
<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName nex.bikinin.website

        Header set Access-Control-Allow-Headers "ORIGIN, X-REQUESTED-WITH, CONTENT-TYPE"
        Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, PUT, DELETE"
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Credentials true
        Header set X-XSS-Protection 1;mode=block
        Header set X-Frame-Options SAMEORIGIN
        Header set X-Content-Type-Options nosniff
        Header set Strict-Transport-Security "max-age=15552000; includeSubDomains;preload"
        Header set Referrer-Policy strict-origin-when-cross-origin
        Header set Access-Control-Max-Age 60000

        ProxyPreserveHost On
        ProxyRequests Off
        ProxyVia On
        ProxyPass / http://127.0.0.1:81/
        ProxyPassReverse / http://127.0.0.1:81/

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
  • Enable mod rewrite, headers, http2, proxy, proxy_http lalu restart service apache2
root@ubuntu-2204:~# a2enmod rewrite
root@ubuntu-2204:~# a2enmod headers
root@ubuntu-2204:~# a2enmod http2
root@ubuntu-2204:~# a2enmod proxy
root@ubuntu-2204:~# a2enmod proxy_http
root@ubuntu-2204:~# a2ensite nex.bikinin.website.conf
root@ubuntu-2204:~# systemctl restart apache2

  • Akses nextcloud lewat browser dengan url: http://nex.bikinin.website
  • buat admin user > install recommended apps

herdiana3389

A system administrator with skills in system administration, virtualization, linux, windows, networking, cloud computing, container, etc.