樹莓派利用Docker實現NextCloud


如何初始化和設置樹莓派,請參考我另外一篇博文,好像還沒寫,哈哈。

言歸正傳,我們來說一下,如何在樹莓派利用Docker實現NextCloud,個人感覺使用docker實現,比直接安裝方便太多,前提是你要稍微熟悉下Docker和編排。

1、Docker規划

首先確認需要使用適用樹莓派的nextcloud的fpm封裝,不使用apache版本,降低資源消耗,方便配置https。對nextcloud的卷的規划,需要適應后期版本更新的需求。根據需要完成下面的容器規划。

所有的卷都規划到home目錄下的nextcloud目錄下,方便管理。除了nextcloud所需要的data目錄,這個是單獨掛載了一個硬盤作為存儲。

 2、編寫編排文件

根據容器的規划,完成編排文件的編寫。

docker-compose.yml 

version: '2'

volumes:
  nextcloud:
  db:

services:
  db:
    image: jsurf/rpi-mariadb
    restart: always
    command: --transaction-isolation=READ-COMMITTED --binlog-format=ROW
    volumes:
      - ./db:/var/lib/mysql
    environment:
      - MYSQL_ROOT_PASSWORD=root@123
      - MYSQL_PASSWORD=nextcloud@123
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud

  app:
    image: arm32v7/nextcloud:fpm
    privileged: true
    links:
      - db
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
      - MYSQL_PASSWORD=nextcloud@123
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    volumes:
      - ./nextcloud/html:/var/www/html
      - ./nextcloud/custom_apps:/var/www/html/custom_apps
      - ./nextcloud/config:/var/www/html/config
      - /data:/var/www/html/data
    restart: always

  web:
    image: nginx
    restart: always
    ports:
      - 80:80
      - 443:443
    environment:
      TZ : 'Asia/Shanghai'
    links:
      - app
    volumes_from:
      - app
    volumes:
      - ./nextcloud/html:/var/www/html
      - ./nginx/conf.d:/etc/nginx/conf.d
      - ./nginx/sslcerts:/etc/nginx/sslcerts

  redis:
    image: redis
    volumes_from:
      - app
    restart: always

3、安裝Docker

curl -fsSL get.docker.com -o get-docker.shsudo sh get-docker.sh --mirror Aliyun

可以把當前用戶加入到 docker 組,以便這個用戶能方便的使用 docker 命令

sudo usermod -aG docker 當前用戶

docker-compose 是基於 python 的一個 docker 編排工具

apt-get install docker-compose

4、安裝Portainer

Portainer是一個可視化的容器鏡像的圖形管理工具,方便后期對容器的啟停和管理,該軟件提供了很便利的日志查詢、容器內操作及容器網絡管理。

#下載 Docker 圖形化界面 portainer
sudo docker pull portainer/portainer
#創建 portainer 容器
sudo docker volume create portainer_data
#運行 portainer
sudo docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

5、准備volumes目錄

根據前期的規划,為nextcloud掛載外部存儲,這個請參考其他的文檔了。對於配置文件和其他的東西,都在home目錄下創建好主目錄即可,比如我這里,就在/home/pi/下創建了nextcloud目錄,並將編排文件放到了該目錄下。

6、准備nginx相應配置文件和ssl證書

需要根據規划,對nginx的配置文件,及證書進行准備。ssl證書可以到阿里雲去申請免費證書。

nginx/conf.d/default.conf

upstream php-handler {
    server app:9000;    # app為docker容器的名稱,9000為nextcloud fpm的端口
} server { listen
80; listen [::]:80; server_name xxx; # 修改為自己的域名 # enforce https return 301 https://$server_name:443$request_uri; } server { listen 443 ssl http2; listen [::]:443 ssl http2; server_name xxx; # 修改為自己的域名 # Use Mozilla's guidelines for SSL/TLS settings # https://mozilla.github.io/server-side-tls/ssl-config-generator/ # NOTE: some settings below might be redundant ssl_certificate /etc/nginx/sslcerts/xxx.pem; # 替換為自己證書文件名 ssl_certificate_key /etc/nginx/sslcerts/xxx.key; # 替換為自己證書文件名 # Add headers to serve security related headers # Before enabling Strict-Transport-Security headers please read into this # topic first. #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; add_header Strict-Transport-Security 15552000; add_header X-Frame-Options SAMEORIGIN; # Remove X-Powered-By, which is an information leak fastcgi_hide_header X-Powered-By; # Path to the root of your installation root /var/www/html; # 此處需要對應nextcloud的文件目錄 # The following 2 rules are only needed for the user_webfinger app. # Uncomment it if you're planning to use this app. #rewrite ^/.well-known/host-meta /public.php?service=host-meta last; #rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last; # The following rule is only needed for the Social app. # Uncomment it if you're planning to use this app. #rewrite ^/.well-known/webfinger /public.php?service=webfinger last; location = /.well-known/carddav { return 301 $scheme://$host:$server_port/remote.php/dav; } location = /.well-known/caldav { return 301 $scheme://$host:$server_port/remote.php/dav; } # set max upload size client_max_body_size 512M; fastcgi_buffers 64 4K; # Enable gzip but do not remove ETag headers gzip on; gzip_vary on; gzip_comp_level 4; gzip_min_length 256; gzip_proxied expired no-cache no-store private no_last_modified no_etag auth; gzip_types application/atom+xml application/javascript application/json application/ld+json application/manifest+json application/rss+xml application/vnd.geo+json application/vnd.ms-fontobject application/x-font-ttf application/x-web-app-manifest+json application/xhtml+xml application/xml font/opentype image/bmp image/svg+xml image/x-icon text/cache-manifest text/css text/plain text/vcard text/vnd.rim.location.xloc text/vtt text/x-component text/x-cross-domain-policy; # Uncomment if your server is build with the ngx_pagespeed module # This module is currently not supported. #pagespeed off; location / { rewrite ^ /index.php$request_uri; } location ~ ^\/(?:build|tests|config|lib|3rdparty|templates|data)\/ { deny all; } location ~ ^\/(?:\.|autotest|occ|issue|indie|db_|console) { deny all; } location ~ ^\/(?:index|remote|public|cron|core\/ajax\/update|status|ocs\/v[12]|updater\/.+|oc[ms]-provider\/.+)\.php(?:$|\/) { fastcgi_split_path_info ^(.+?\.php)(\/.*|)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTPS on; # Avoid sending the security headers twice fastcgi_param modHeadersAvailable true; # Enable pretty urls fastcgi_param front_controller_active true; fastcgi_pass php-handler; fastcgi_intercept_errors on; fastcgi_request_buffering off; } location ~ ^\/(?:updater|oc[ms]-provider)(?:$|\/) { try_files $uri/ =404; index index.php; } # Adding the cache control header for js, css and map files # Make sure it is BELOW the PHP block location ~ \.(?:css|js|woff2?|svg|gif|map)$ { try_files $uri /index.php$request_uri; add_header Cache-Control "public, max-age=15778463"; # Add headers to serve security related headers (It is intended to # have those duplicated to the ones above) # Before enabling Strict-Transport-Security headers please read into # this topic first. #add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload;"; # # WARNING: Only add the preload option once you read about # the consequences in https://hstspreload.org/. This option # will add the domain to a hardcoded list that is shipped # in all major browsers and getting removed from this list # could take several months. add_header X-Content-Type-Options nosniff; add_header X-XSS-Protection "1; mode=block"; add_header X-Robots-Tag none; add_header X-Download-Options noopen; add_header X-Permitted-Cross-Domain-Policies none; add_header Referrer-Policy no-referrer; # Optional: Don't log access to assets access_log off; } location ~ \.(?:png|html|ttf|ico|jpg|jpeg|bcmap)$ { try_files $uri /index.php$request_uri; # Optional: Don't log access to other assets access_log off; } }

 

7、執行 Docker Compose

一切准備好后,執行編排文件,會將docker下載好,並創建好卷和網絡。必須在docker-compose.yml 文件所在目錄。

docker-compose up -d

8、配置NextCloud

一切完成后,進入Portainer,查看容器運行情況,一切正常,就可以通過你配置的地址打開頁面了。直接進入到nextcloud的配置界面,創建一個用戶名密碼,就可以登錄了。

 

9、更新NextCloud

如果nextcloud版本有更新,可以刪除現有NextClolud  Docker鏡像進行更新

docker stop arm32v7/nextcloud:fpm
docker rm   arm32v7/nextcloud:fpm
rm     -rvf /home/pi/nextcloud/nextcloud/html

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM