【云计算】Docker部署Nextcloud网盘并实现随地公网远程访问

配置文件

切换root权限,新建一个nextcloud的文件夹,进入该目录,创建docker-compose.yml

sh 复制代码
[cps@localhost ~]$ su root
Password: 666666
[root@localhost cps]# ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
[root@localhost cps]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    d2c94e258dcb   13 months ago   13.3kB
centos        7         eeb6ee3f44bd   2 years ago     204MB
[root@localhost cps]# pwd
/home/cps
[root@localhost cps]# mkdir nextcloud
[root@localhost cps]# cd nextcloud/
[root@localhost nextcloud]# touch docker-compose.yml
[root@localhost nextcloud]# gedit docker-compose.yml 
yml 复制代码
version: '2.1'

volumes:
  nextcloud:
  db:

services:
  db:
    image: mysql
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    volumes:
      - /home/cps/nextcloud/mysql:/var/lib/mysql
    environment: 
      - MYSQL_ROOT_PASSWORD=12345678
      - MYSQL_PASSWORD=nextcloud
      - MYSQL_DATABASE=nextcloud
      - MYSQL_USER=nextcloud
    
  app:
    image: nextcloud
    ports:
      - 8008:80
    links:
      - db
    volumes:
      - /home/cps/nextcloud/nextcloud:/var/www/html

安装部署

docker-compose up -d

本地访问

http:localhost:8008

Nextcloud设置

等待一会

内网穿透

cpolar安装

sh 复制代码
curl -L https://www.cpolar.com/static/downloads/install-release-cpolar.sh | sudo bash
sudo systemctl enable cpolar
sudo systemctl start cpolar

cpolar登录web

  1. https://www.cpolar.com/官网注册账号
  2. cpolar安装成功后,在外部浏览器上访问Linux 的9200端口即:【http://服务器的局域网ip:9200
  3. 使用cpolar账号登录,登录后即可看到cpolar web 配置界面,在仪表盘下创建隧道。

配置可信任域名

'trusted_domains' => 添加可信任域名5256185a.r1.vip.cpolar.cn

sh 复制代码
[root@localhost nextcloud]# find / -name "config.php"
find: '/run/user/1001/gvfs': Permission denied
/var/lib/docker/volumes/ad49ff6c8750b8ec4841ac640f8c6b1a4f49fece3a97401bd714d072e1cedda3/_data/config/config.php
[root@localhost nextcloud]# gedit /var/lib/docker/volumes/ad49ff6c8750b8ec4841ac640f8c6b1a4f49fece3a97401bd714d072e1cedda3/_data/config/config.php
[root@localhost nextcloud]# cat /var/lib/docker/volumes/ad49ff6c8750b8ec4841ac640f8c6b1a4f49fece3a97401bd714d072e1cedda3/_data/config/config.php
<?php
$CONFIG = array (
  'htaccess.RewriteBase' => '/',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'apps_paths' => 
  array (
    0 => 
    array (
      'path' => '/var/www/html/apps',
      'url' => '/apps',
      'writable' => false,
    ),
    1 => 
    array (
      'path' => '/var/www/html/custom_apps',
      'url' => '/custom_apps',
      'writable' => true,
    ),
  ),
  'instanceid' => 'ocq23pxvlmom',
  'passwordsalt' => 'uzZUljuHVuZ8MtsoKF6pljCMUskNwo',
  'secret' => 'hevqvGaITGj/9zns/PpMJZ2L98xCpl0g6iS76aeB9/1siZpZ',
  'trusted_domains' => 
  array (
    0 => 'localhost:8008',
    1 => '5256185a.r1.vip.cpolar.cn',
  ),
  'datadirectory' => '/var/www/html/data',
  'dbtype' => 'mysql',
  'version' => '23.0.0.10',
  'overwrite.cli.url' => 'http://localhost:8008',
  'dbname' => 'nextcloud',
  'dbhost' => 'db',
  'dbport' => '',
  'dbtableprefix' => 'oc_',
  'mysql.utf8mb4' => true,
  'dbuser' => 'nextcloud',
  'dbpassword' => 'nextcloud',
  'installed' => true,
);

确保docker容器NextCloud、Mysql已开启

sh 复制代码
[root@localhost nextcloud]# docker ps
CONTAINER ID   IMAGE       COMMAND                  CREATED      STATUS      PORTS                                   NAMES
1e9178afddf5   nextcloud   "/entrypoint.sh apac..."   2 days ago   Up 2 days   0.0.0.0:8008->80/tcp, :::8008->80/tcp   nextcloud_app_1
e504c967c5b5   mysql       "docker-entrypoint.s..."   2 days ago   Up 2 days   3306/tcp, 33060/tcp                     nextcloud_db_1

公网访问

问题与解决

bash: docker-compose: command not found...

[root@localhost nextcloud]# docker-compose up -d
bash: docker-compose: command not found...
  1. 安装工具源

sudo yum -y install epel-release

  1. docker-compose依赖python,安装 python-pip 模块

sudo yum install python-pip

  1. 下载docker-compose 安装包

wget https://github.com/docker/compose/releases/download/1.14.0-rc2/docker-compose-Linux-x86_64

  1. 重命名工具 docker-compose 名称,并移动到系统可执行目录

mv docker-compose-Linux-x86_64 /usr/local/bin/docker-compose

  1. 修改文件的可执行属性

chmod +x /usr/local/bin/docker-compose

  1. 验证

docker-compose -version


mysql 很多Waiting。。。镜像pull不下来

  1. 配置文件
sh 复制代码
 vi   /etc/docker/daemon.json
json 复制代码
{ 
 "registry-mirrors": ["https://studk.mirror.aliyuncs.com","http://f1361db2.m.daocloud.io"] 
} 
  1. 重启服务
sh 复制代码
sudo systemctl restart docker

通过不被信任的域名访问

'trusted_domains' =>
  array (
   0 => 'localhost',
   1 => '这里写域名',
),

参考

我的docker随笔19:Nextcloud部署
https://juejin.cn/post/6982782635546411015

docker-compose: command not found问题的两种常用方法
https://blog.csdn.net/sinat_17358633/article/details/128764036

容器技术.合版.v0.095.增改.学生版.pdf 【3.3.2 镜像加速】

docker镜像pull不下来最终解决方法
https://www.cnblogs.com/wang50902/p/11378202.html

Docker 配置国内源加速(2023/05/14)
https://blog.csdn.net/qq_44797987/article/details/112681224

docker 报错ERROR: client version 1.22 is too old. Minimum supported API version is 1.24···
https://blog.csdn.net/zwy3327078581/article/details/136037950

如何在Linux系统使用Docker部署Nextcloud网盘并实现随地公网远程访问
https://cloud.tencent.com/developer/article/2392880

Nextcloud通过不被信任的域名访问解决方法 Nextcloud 您正在访问来自不信任域名的服务器
https://blog.51cto.com/u_15296600/3008162

相关推荐
VinciYan2 小时前
基于Jenkins+Docker的自动化部署实践——整合Git与Python脚本实现远程部署
python·ubuntu·docker·自动化·jenkins·.net·运维开发
tntlbb3 小时前
Ubuntu20.4 VPN+Docker代理配置
运维·ubuntu·docker·容器
Gabriel_liao4 小时前
Docker安装Neo4j
docker·容器·neo4j
豆豆豆豆变7 小时前
Docker轻量级可视化工具Portainer
docker·容器·自动化运维
花晓木7 小时前
k8s etcd 数据损坏处理方式
容器·kubernetes·etcd
运维&陈同学7 小时前
【模块一】kubernetes容器编排进阶实战之基于velero及minio实现etcd数据备份与恢复
数据库·后端·云原生·容器·kubernetes·etcd·minio·velero
花晓木7 小时前
k8s备份 ETCD , 使用velero工具进行备份
容器·kubernetes·etcd
大熊程序猿7 小时前
xxl-job docker 安装
运维·docker·容器
shelby_loo8 小时前
使用 Docker 在 Ubuntu 下部署 Cloudflared Tunnel 服务器
服务器·ubuntu·docker
咏颜8 小时前
Ubuntu离线安装Docker容器
linux·运维·服务器·经验分享·ubuntu·docker