docker使用nextcloud与mysql搭建自己的网盘

docker使用nextcloud与mysql搭建自己的网盘

安装docker-compose

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

修改权限

1
➜ sudo chmod +x /usr/local/bin/docker-compose

##安装nextcloud及mariadb镜像

1
2
docker pull wonderfall/nextcloud
docker pull mariadb:10

创建docker-compose文件并运行

docker-compose.yml内容如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
nextcloud:
image: wonderfall/nextcloud
container_name: nextcloud_web
links:
- nextcloud-db:nextcloud-db
environment:
- UID=1000
- GID=1000
- UPLOAD_MAX_SIZE=5G
- APC_SHM_SIZE=32M # 此处设置128M可能会报apc_mmap错误问题
- OPCACHE_MEM_SIZE=128
- CRON_PERIOD=15m
- TZ=Aisa/Shanghai
- ADMIN_USER=登录账户
- ADMIN_PASSWORD=登录密码
- DOMAIN=localhost
- DB_TYPE=mysql
- DB_NAME=nextcloud
- DB_USER=nextcloud
- DB_PASSWORD=数据库nextcloud的密码
- DB_HOST=nextcloud-db
volumes:
# 文件存放于/home/heroin/nextcloud目录下,不存在则自动新建
- /home/heroin/nextcloud/data:/data
- /home/heroin/nextcloud/config:/config
- /home/heroin/nextcloud/apps:/apps2
- /home/heroin/nextcloud/themes:/nextcloud/themes
expose:
- 8888
ports:
- 0.0.0.0:8888:8888/tcp
restart: always

nextcloud-db:
image: mariadb:10
container_name: nextcloud_db
volumes:
- /home/heroin/nextcloud/db:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=数据库root的密码
- MYSQL_DATABASE=nextcloud
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=数据库nextcloud的密码
restart: always

打开到docker-compose.yml同级目录下

1
2
3
docker-compose up -d
Creating nextcloud_db ... done
Creating nextcloud_web ... done

查看容器日志

1
2
3
docker ps -a 
docker logs nextcloud_db
docker logs nextcloud_web

查看nextcloud_web日志时出现NOTICE: PHP message: PHP Fatal error: apc_mmap: Failed to mmap 134217728 bytes. Is your apc.shm_size too large? in Unknown on line 0. 此问题由于设置APC_SHM_SIZE=128M,值过大导致,修改为32M后解决

在网址中输入\:8888即可查看结果

网页提示该ip不安全,需要在config.php中加入域名信任

打开到/home/heroin/nextcloud/config目录

vi config.php

1
2
3
4
5
6
> 'trusted_domains' =>
> array (
> 0 => 'localhost',
> 1 => '<ip>',
> ),
>

在\处修改为服务器ip即可。

添加域名解析