【云计算】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

相关推荐
dessler21 分钟前
Linux系统-ubuntu系统安装
linux·运维·云计算
MonkeyKing_sunyuhua1 小时前
ubuntu22.04 docker-compose安装postgresql数据库
数据库·docker·postgresql
Elastic 中国社区官方博客2 小时前
如何将数据从 AWS S3 导入到 Elastic Cloud - 第 3 部分:Elastic S3 连接器
大数据·elasticsearch·搜索引擎·云计算·全文检索·可用性测试·aws
九河云2 小时前
如何选择适合的AWS EC2实例类型
服务器·云计算·aws
追风林2 小时前
mac m1 docker本地部署canal 监听mysql的binglog日志
java·docker·mac
€☞扫地僧☜€3 小时前
docker 拉取MySQL8.0镜像以及安装
运维·数据库·docker·容器
茶馆大橘3 小时前
微服务系列六:分布式事务与seata
分布式·docker·微服务·nacos·seata·springcloud
全能全知者4 小时前
docker快速安装与配置mongoDB
mongodb·docker·容器
Huaqiwill4 小时前
Ubuntun搭建并行计算环境
linux·云计算
为什么这亚子6 小时前
九、Go语言快速入门之map
运维·开发语言·后端·算法·云原生·golang·云计算