Myluzh Blog

Docker部署Nextcloud

发布时间: 2022-8-16 文章作者: myluzh 分类名称: Docker 朗读文章


安装docker
curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

配置docker国内源
阿里云镜像获取地址:https://cr.console.aliyun.com/cn-hangzhou/instances/mirrors,登陆后左侧菜单选中镜像加速器就可以看到你的专属地址了
vi /etc/docker/daemon.json 中写入如下内容,把下面的地址替换成自己的专属加速地址
{ "registry-mirrors": ["https://n5gqv0vl.mirror.aliyuncs.com"]}
完成后重新启动服务:
systemctl daemon-reload
systemctl restart docker
查看源是否配置成功
docker info

安装mysql
docker serach mysql
docker pull mysql
docker images
docker run -d --name mysql --restart=always -p 3306:3306 -e MYSQL_ROOT_PASSWORD=QWER1234  -e MYSQL_DATABASE=nextcloud mysql
docker exec -it mysql bash


拉取nextcloud
docker search nextcloud
docker pull nextcloud

查询nextcloud镜像是否下载完成
docker images | grep nextcloud

查看镜像详细信息
docker inspect c805c152803c

创建并启动docker容器
docker run -d --restart=always --name nextcloud -p 80:80 -v /home/docker/nextcloud/:/var/www/html/ --link mysql nextcloud:latest
# 参数解释:
# docker run:启动容器
# -d:后台启动
# --restart=always:docker重启该容器跟着重启
# --nmae nextcloud:自定义容器名称
# -p 80:80:将服务器的80端口映射到容器的80端口,前面的80代表服务器,后面的80代表容器端口
# -v 文件夹映射
# nextcloud:latest:选择启动的镜像和版本

查询nextcloud是否启动
docker ps
docker inspect 57a357e60bec
curl 127.0.0.1


如果要使用https
本地安装nginx 反向代理到80端口即可,配置文件如下:
server {
    listen 8062 ssl;
    server_name home.itho.cn 127.0.0.1 localhost 172.16.10.10;

    if ($http_host !~* ^(172\.16\.10\.10|home\.itho\.cn)(:[0-9]+)?$) {
        return 444;
    }

    ssl_certificate /etc/nginx/conf.d/ssl/itho.cn/fullchain.pem;
    ssl_certificate_key /etc/nginx/conf.d/ssl/itho.cn/privkey.pem;
    add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;

    location / {
        proxy_pass http://172.16.10.221;
        proxy_set_header Host 172.16.10.221;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        proxy_set_header X-Nginx-Proxy true;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    location /.well-known/carddav {
        return 301 $scheme://$host/remote.php/dav;
    }
    location /.well-known/caldav {
        return 301 $scheme://$host/remote.php/dav;
    }

    error_page 400 https://$host:8062$request_uri;
    error_page 497 https://$host:8062$request_uri;

config/config.php需要修改一下:
'overwriteprotocol' => 'https',
'overwritehost'     => 'h.itho.cn:8062',
'overwrite.cli.url' => 'https://h.itho.cn:8062',

标签: nextcloud docker

发表评论