Docker中compose安装owncloud

ownCloud 跨平台支持 Windows、Mac、Android、iOS、Linux 等平台,而且还提供了网页版和 WebDAV 形式访问,因此你可以在任何电脑、手机上都能轻松获取你的文件了。

一、安装Docker

在Centos中,使用脚本直接安装Docker

## 确保 yum 包更新到最新。
sudo yum -y update

## 卸载旧版本
sudo yum remove docker  docker-common docker-selinux docker-engine
<!-- more -->
## 安装需要的软件包
sudo yum install -y yum-utils device-mapper-persistent-data lvm2 

## 安装container-selinux
yum  install -y http://mirror.centos.org/centos/7/extras/x86_64/Packages/container-selinux-2.107-1.el7_6.noarch.rpm

## 设置yum源
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

## 安装
sudo yum -y install docker-ce

## 设置开机启动
sudo systemctl enable docker

## 启动docker
sudo systemctl start docker

## 显示版本
docker version

二、Compose 安装

Linux 上我们可以从 Github 上下载它的二进制包来使用,最新发行的版本地址:https://github.com/docker/compose/releases
运行以下命令以下载 Docker Compose 的当前稳定版本:

curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

将可执行权限应用于二进制文件:

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

三、安装owncloud

1. 创建yml文件

在适当的目录中,创建docker-compose.yml文件,文件内容:

version: '2.1'

volumes:
  files:
    driver: local
  mysql:
    driver: local
  backup:
    driver: local
  redis:
    driver: local

services:
  owncloud:
    image: owncloud/server:${OWNCLOUD_VERSION}
    restart: always
    ports:
      - ${HTTP_PORT}:8080
    depends_on:
      - db
      - redis
    environment:
      - OWNCLOUD_DOMAIN=${OWNCLOUD_DOMAIN}
      - OWNCLOUD_DB_TYPE=mysql
      - OWNCLOUD_DB_NAME=owncloud
      - OWNCLOUD_DB_USERNAME=owncloud
      - OWNCLOUD_DB_PASSWORD=owncloud
      - OWNCLOUD_DB_HOST=db
      - OWNCLOUD_ADMIN_USERNAME=${ADMIN_USERNAME}
      - OWNCLOUD_ADMIN_PASSWORD=${ADMIN_PASSWORD}
      - OWNCLOUD_MYSQL_UTF8MB4=true
      - OWNCLOUD_REDIS_ENABLED=true
      - OWNCLOUD_REDIS_HOST=redis
    healthcheck:
      test: ["CMD", "/usr/bin/healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - files:/mnt/data

  db:
    image: webhippie/mariadb:latest
    restart: always
    environment:
      - MARIADB_ROOT_PASSWORD=owncloud
      - MARIADB_USERNAME=owncloud
      - MARIADB_PASSWORD=owncloud
      - MARIADB_DATABASE=owncloud
      - MARIADB_MAX_ALLOWED_PACKET=128M
      - MARIADB_INNODB_LOG_FILE_SIZE=64M
    healthcheck:
      test: ["CMD", "/usr/bin/healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - mysql:/var/lib/mysql
      - backup:/var/lib/backup

  redis:
    image: webhippie/redis:latest
    restart: always
    environment:
      - REDIS_DATABASES=1
    healthcheck:
      test: ["CMD", "/usr/bin/healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 5
    volumes:
      - redis:/var/lib/redis

2. 创建环境配置文件

cat << EOF > .env
OWNCLOUD_VERSION=10.5
OWNCLOUD_DOMAIN=localhost
ADMIN_USERNAME=admin
ADMIN_PASSWORD=admin
HTTP_PORT=8080
EOF
配置文件 描述 例如
OWNCLOUD_VERSION ownCloud 版本 latest
OWNCLOUD_DOMAIN 域名 localhost
ADMIN_USERNAME 管理员账号 admin
ADMIN_PASSWORD 管理员密码 123456
HTTP_PORT 访问端口 latest

3. 安装

docker-compose up -d

4. 查看结果

Name                              Command                     State   Ports
__________________________________________________________________________________________
ownclouddockerserver_db_1         … /bin/s6-svscan /etc/s6    Up      3306/tcp
ownclouddockerserver_owncloud_1   … /usr/bin/owncloud server  Up      0.0.0.0:8080->8080/tcp
ownclouddockerserver_redis_1      … /bin/s6-svscan /etc/s6    Up      6379/tcp

5. 运行测试

6. 文件目录

上传的文件会在Docker对应的volumes目录中

/var/lib/docker/volumes/owncloud_files/_data/files/用户名

如果未设置启用服务器端加密,则文件就是网盘中的原文件,可以直接拿出来用

7. Nginx反向代理

7.1 进入容器内部

docker exec -it owncloud_owncloud_1 /bin/bash

7.2 修改配置文件

找到/var/www/owncloud目录下的config/config.php配置文件,修改配置

  'trusted_domains' =>
  array (
    0 => 'pan.zengwu.com.cn',                           // 添加自己的域名
    1 => 'localhost'
  ),

  'overwrite.cli.url' => 'https://pan.zengwu.com.cn/', // 修改为自己的域名

7.3 配置nginx

# http 转 https
server{
  listen 80;
  return 301 https://$host$request_uri;
}

# https域名
server{
  listen 443 ssl;
  server_name pan.zengwu.com.cn;

  index   index.html;
  ssl on;
  ssl_certificate /etc/nginx/key/pan.zengwu.com.cn.pem;
  ssl_certificate_key /etc/nginx/key/pan.zengwu.com.cn.key;
  ssl_session_timeout 5m;
  ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  ssl_prefer_server_ciphers on;

  location / {
    proxy_pass http://localhost:8080/;

    # header 开始
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   Cookie $http_cookie;
    # header 结束

    client_max_body_size 5G;  # 允许上传的文件大小
  }
}
0%