在这里插入图片描述最近有了新手机,旧手机也闲置了,由于之前一直在寻找平价的NAS替代方案,旧手机在抽屉躺了N天后,我决定让它重新焕发光彩,努力工作,继续拉磨。
这个时代的旧手机可以满足NAS的基本配置需求,内存、硬盘、内置电源、WIFI模块、快速接口,简直是理想中的NAS形态,但是散热、ROOT和性能是个短板,不过也不是大问题!
这里的方案也不需要ROOT!

网页端,这个是手机上用Docker部署好的个人网盘页面。
在这里插入图片描述手机端。
在这里插入图片描述容器运行
在这里插入图片描述

什么NAS?
可道云,这也不算是个正经的NAS系统,但是私有云存储&协同办公,又是PC端桌面的操作界面,电脑手机使用都蛮方便,也算是能达到我个人的使用需求。
平时主要存存工具软件,存放我那越来越难以安置的知识库。
地址:https://kodcloud.com/

一般来说在手机上使用Linux系统都是基于termux APP版linux,但是Docker仍然不能在termux版linux里运行,需要Termux上装Qemu虚拟机,然后再在Qemu里装alpine linux,这种套娃式的操作蛮费事,对于没有耐心的盆友来说是一个噩梦般的操作过程,所幸的是有人把Termux+Qemu虚拟机+Alpine Linux整合好了,名为alpine term,极大简化了部署流程,下载Alpine-termux这个APP安装就能用,不过这个安装就能用也只是一个相对的概念,对于我们使用Docker部署应用来说还是有一段路需要走,有一些坑需要踩。

下面正式进入旧手机改造流程,祝我们成功,为了我们的折腾精神。🍻

  • 准备工作:
    小风扇、旧手机,电源线、有网络的WIFI、一台电脑、VMware虚拟机、Shell终端软件

1、下载Alpine-termux APP

Alpine-termux APP概念:
Alpine-termux是APP,Alpine系统是Alpine-termux APP中的一个虚拟机,你可以将Alpine-termux理解为VMware或者Hyper-V或其它虚拟机软件,而Alpine是在虚拟机里运行的Linux系统。

GitHub项目页
https://github.com/FakeRajbhx/alpine-term
APP大概500多M,直接使用GitHub文件提速下载以下APK:https://gh.api.99988866.xyz/
https://github.com/FakeRajbhx/alpine-term/releases/download/New/alpine-term-v16.0-release.apk

2、初始化和登录

下载安装后初始化开机,开机后,登录系统,用户:alpine 密码: alpine
切换到root账户,输入sudo -s
密码为 alpine ,接着修改root密码, 输入 passwd ,需要输入两次密码。

root登录后会显示

C:\Users\admin>ssh root@172.16.12.21 -p 8022
The authenticity of host '[172.16.12.21]:8022 ([172.16.12.21]:8022)' can't be established.
ECDSA key fingerprint is SHA256:T7ViBHC8k6XKW4kY/jor/CRLynwZnv5QF88sMmfTreA.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '[172.16.12.21]:8022' (ECDSA) to the list of known hosts.
root@172.16.12.21's password:

############################################################

Welcome to the Alpine Linux!

This operating system uses a package manager called 'apk'.
Here is a quick guide how to use it:

  apk add {pkg name}   - install package
  apk del {pkg name}   - uninstall package
  apk info             - list installed packages
  apk info {pkg name}  - show information about package
  apk search {query}   - search for package
  apk update           - update package lists
  apk upgrade          - upgrade installed packages
  apk audit            - show file system changes

Check file '/home/alpine/README' for details about the
current setup of the operating system.

See <https://wiki.alpinelinux.org> for the information
about administrating Alpine systems.

############################################################

Things to do on the first login:

 1. Change password.
 2. Set timezone by executing 'sudo setup-timezone'.
 3. Change this message by editing /etc/motd.
 4. Change login banner by editing /etc/issue.
 5. Check for package updates.

############################################################

root@alpine-term ~ #

3、ssh和root配置

下面的sed命令是在手机端操作的,毕竟此时无法通过电脑终端连接Alpine-termux,如果觉得在手机上一个字母一个字母输入麻烦,就直接vi /etc/ssh/sshd_config配置文件,将PasswordAuthentication和PermitRootLogin的no改成yes,这速度比一个一个输入快多了!

问题:为什么不把命令复制在手机上再在手机命令行里粘贴?
因为Alpine-termux的手机端似乎对长文本的输入支持不友好,比如博主在将以下命令复制粘贴在手机端命令行后,是现实不完整的,即使强行回车,也会报错,所以还是直接在配置文件将no改为yes是最省事的!

系统默认是禁止ssh密码登录的,所以需要先开启它,输入:

sed -i ‘s/PasswordAuthentication no/PasswordAuthentication yes/g’ /etc/ssh/sshd_config  

如果还需要开机root用户登录的话,输入

sed -i ‘s/PermitRootLogin no/PermitRootLogin yes/g’ /etc/ssh/sshd_config

然后重启启动sshd服务,输入

service sshd restart  

重启完成就配置好了。

4、alpine到termux的端口映射

映射ssh的22端口(方便电脑操作,只想手机操作就忽略这个步骤)
因为是Qemu套娃,所以需要映射ssh的22端口,开机完成后,手指在软件的左上方向右滑,会出现菜单,
如下所示:

[1]QEMU

[2]/dev/ttyS0
Waiting for login on /dev/ttyS0...

[3]/dev/ttyS1
Waiting for login on /dev/ttyS1...

[4]/dev/ttyS2
Waiting for login on /dev/ttyS2...

[5]/dev/ttyS3
Waiting for login on /dev/ttyS3...

选择 [2]/dev/ttyS0
输入:

ssh root@127.0.0.1 -p 22

映射ssh的22端口到手机的8022端口,选择 [1]QEMU,
输入

hostfwd_add tcp::8022-:22

【注意事项1】这个映射端口的命令每次重启Alpine Term 都需要重新设置一次,建议常驻后台。
执行上面的指令后就可以远程ssh手机的8022端口。这样当手机和电脑处于同一局域网的时候我们就能在电脑上通过FinalShell远程登录手机的Termux模拟终端了。
在电脑上操作终端复制命令比较方便。

【注意事项2】如果你中途出门去公司或其它公共场合,连接了其它wifi,只要没主动关闭Alpine Term APP后台,可以直接在wifi设置里查看新的IP,使用新IP+8022访问模拟终端。

5、网络配置

在alpine中,使用vi编辑器:

vi /etc/network/interfaces

添加如下配置
这里使用dhcp自动获取IP,Alpine虚拟机在这种套娃式的情境下没必要设置固定IP。

auto lo  
iface lo inet loopback  
auto eth0  
iface eth0 inet dhcp

保存后重启网络

/etc/init.d/networking restart

配置DNS地址

vi /etc/resolv.conf

添加如下配置

nameserver 8.8.8.8
nameserver 8.8.4.4

resolv.conf修改后没有重启操作,直接就生效了!

这样alpine就能访问互联网了,如果还是没网,就重启APP重新配置!

6、配置APK源

查看系统版本

cat /etc/alpine-release
3.13.12

方案一、使用阿里镜像 https://mirrors.aliyun.com

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories

方案二、使用科大镜像 http://mirrors.ustc.edu.cn

sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories

在上面方案中找到对应系统版本的源版本,这里使用科大的镜像源

http://mirrors.ustc.edu.cn/alpine/v3.13/

找到的源写入以下文件

vi /etc/apk/repositories

在文件中修改以下信息
顺便将最下面的testing注释掉,因为源里没有testing这个目录,不注释掉会导致报错

# Main package repositories.
http://mirrors.ustc.edu.cn/alpine/v3.13/main
http://mirrors.ustc.edu.cn/alpine/v3.13/community

# Testing repository.
# You can install packages from this repository with:
# apk add package@testing
#@testing http://mirrors.ustc.edu.cn/alpine/v3.13/testing

或者也可以使用sed替换

sed -i 's/文本/文本/g' /etc/apk/repositories

更新仓库

apk update

升级软件包,后面加–force-broken-world跳过一些问题

apk upgrade --available --force-broken-world

7、重新进入系统

启动alpine-term APP后等待系统加载完成。
系统加载完成后登录alpine-term使用alpine账号登录:

alpine/alpine

进入alpine系统后,使用root用户登录系统:

root/xxxxx

之后在alpine系统命令行输入:

ssh root@127.0.0.1 -p 22

然后手指在软件的左上方向右滑,进行端口映射,选择 [1]QEMU输入:

hostfwd_add tcp::8022-:22

之后就可以在电脑端使用alpine-term IP加上8022远程访问alpine系统了。

8、安装docker

安装docker

sudo apk add docker

使docker开机启动

sudo rc-update add docker  

开启docker服务

sudo service docker start  

后台启动

sudo setsid containerd  
sudo setsid dockerd

docker启动报错

"failed to mount overlay: no such device storage-driver=overlay2" 

上面的错误表明在尝试挂载 Overlay2 存储驱动时出现了问题
添加以下文件及信息

vi /etc/docker/daemon.json
{"storage-driver"="devicemapper"}

测试

docker info
docker ps

测试成功的信息

root@alpine-term ~ # docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

root@alpine-term ~ # docker info
Client:
 Context:    default
 Debug Mode: false

Server:
 Containers: 0
  Running: 0
  Paused: 0
  Stopped: 0
 Images: 0
 Server Version: 20.10.3
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 7eba5930496d9bbe375fdf71603e610ad737d2b2
 runc version: b9ee9c6314599f1b4a7f497e1f1f856fe433d3b7
 init version:
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.152-0-virt
 Operating System: Alpine Linux v3.13
 OSType: linux
 Architecture: x86_64
 CPUs: 1
 Total Memory: 2.321GiB
 Name: alpine-term
 ID: BYOE:XMQL:NQVM:E2ZZ:RRXQ:HWB4:YB2B:5KNY:R24L:HMLF:REPA:XYZB
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio weight support
WARNING: No blkio weight_device support

DOCKER 安装完成!

9、安装docker compose

curl可能会因为alpine系统网络问题无法下载

curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose

这里直接去PC浏览器下载,然后再通过终端上传到alpine系统
https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64
下载完成后将其上传到目录/usr/local/bin/
修改docker-compose-linux-x86_64为docker-compose

mv docker-compose-linux-x86_64 docker-compose

修改docker-compose权限

chmod 777 docker-compose

查看docker-compose版本

docker-compose -v
Docker Compose version v2.23.3

10、部署个人网盘

前言:

因为Alpine-termux APP和手机本身的限制,有时候拉取镜像会因为网络的问题直接失败。

root@alpine-term /mnt/shared/h1d/kodbox # docker-compose up -d 
[+] Running 0/39 
⠋ db 8 layers [⠀⠀⠀⠀⠀⠀⠀⠀] 0B/0B Pulling 27.9s 
⠧ d4c3c94e5e10 Waiting 13.6s
error pulling image configuration: Get "https://production.cloudflare.docker.com/registry-v2/docker/registry/v2/blobs/sha256/d7/d7a7b84914e9e8f30bd2d3a4114a65dcc076982658d77dce2471f7a8680556ab/data?verify=1715396819-pzw5%2BKmSVyKpEVAUKLWXjUiz93M%3D": net/http: TLS handshake timeout

所以这里我放弃了在Alpine-termux APP虚拟机里直接拉取镜像。

我在电脑端起了一台centos7虚拟机,在centos7中执行docker-compose pull镜像。

1、vmware PC环境(容器部署与迁移)

1.在centos7中安装docker
安装并启动docker服务, 新版本docker会自动安装docker-compose-plugin

 curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
 systemctl enable docker && systemctl start docker

docker compose 用法, 在通过docker compose up启动后, 可以使用docker compose ls查看配置文件位置

docker compose ls

提示:
docker compose命令不存在,可手动安装二进制文件docker-compose并在后续命令中替换。

curl -SL https://github.com/docker/compose/releases/download/v2.23.3/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

2.http方式快速启动
注意:
首先创建一个目录作为项目目录,后面所有命令都在这个目录下执行

mkdir /kodbox && cd /kodbox

需在db.env中设置数据库密码,还有yml中的MYSQL_ROOT_PASSWORD需补充.
创建文件来设置数据库环境变量vim db.env

MYSQL_PASSWORD=test@123
MYSQL_DATABASE=kodbox
MYSQL_USER=kodbox

创建docker-compose.yml 文件

 vim docker-compose.yml

在其中配置映射端口、持久化目录

version: '3.5'

services:
  db:
    image: mariadb:10.6
    restart: always
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    volumes:
      - "./db:/var/lib/mysql"       #./db是数据库持久化目录,可以修改
      # - "./etc/mysql/conf.d:/etc/mysql/conf.d"       #增加自定义mysql配置
    environment:
      - MYSQL_ROOT_PASSWORD=test@123
      - MARIADB_AUTO_UPGRADE=1
      - MARIADB_DISABLE_UPGRADE_BACKUP=1
    env_file:
      - db.env
      
  app:
    image: kodcloud/kodbox
    restart: always
    ports:
      - 8082:80                       #左边8082是使用端口,可以修改
    volumes:
      - "./site:/var/www/html"      #./site是站点目录位置,可以修改
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
    env_file:
      - db.env
    depends_on:
      - db
      - redis

  redis:
    image: redis:alpine
    restart: always

增加自定义mysql配置:
mkdir -p ./etc/mysql/conf.d && vim ./etc/mysql/conf.d/custom.cnf

进入项目目录,执行docker compose up -d启动命令,会自动拉取容器并运行

docker compose up -d

[root@localhost kodbox]# docker compose up -d
WARN[0000] /kodbox/docker-compose.yml: `version` is obsolete
[+] Running 21/24
[+] Running 24/24                                 
 ✔ redis Pulled                                
 ✔ db Pulled                                    
 ✔ app Pulled                                      
   ✔ 4abcf2066143 Already exists                
   ✔ 4b99432ace8a Pull complete               
   ✔ d3a73aae1c86 Pull complete              
   ✔ 9294d9185d89 Pull complete              
   ✔ 0150bd92669e Pull complete             
   ✔ 036a86a4ae38 Pull complete              
   ✔ 75d2a8eea798 Pull complete              
   ✔ 23484683932f Pull complete             
   ✔ b8f832e65336 Pull complete              
   ✔ b483e4a592eb Pull complete                
   ✔ 3a7dde3951ca Pull complete                
   ✔ cfe5bc492e21 Pull complete              
   ✔ 3a23c501ebe9 Pull complete              
   ✔ 048b5f93008a Pull complete             
   ✔ c4a1cf1fe966 Pull complete             
   ✔ 636b4e8a2c46 Pull complete               
   ✔ fed06c53db4e Pull complete              
   ✔ 179134eaf663 Pull complete              
   ✔ a5ce73d87f31 Pull complete             
   ✔ cb96a54eed25 Pull complete              
   ✔ 17f2e044ddce Pull complete               
[+] Running 3/3
 ✔ Container kodbox-redis-1  Started         
 ✔ Container kodbox-db-1     Started          
 ✔ Container kodbox-app-1    Started          

查看启动的容器

[root@localhost kodbox]# docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED              STATUS              PORTS                                                      NAMES
85204045b448   kodcloud/kodbox   "/entrypoint.sh supe…"   About a minute ago   Up About a minute   443/tcp, 9000/tcp, 0.0.0.0:8082->80/tcp, :::8082->80/tcp   kodbox-app-1
d5b5ab5e725b   mariadb:10.6      "docker-entrypoint.s…"   About a minute ago   Up About a minute   3306/tcp                                                   kodbox-db-1
2d376d5abc17   redis:alpine      "docker-entrypoint.s…"   7 days ago           Up About a minute   6379/tcp

访问页面:http://IP:8082
进入页面说明容器运行正常!

现在回到centos7虚拟机停止容器,用不上也可以直接删除容器

docker compose down
或者
docker stop $(docker ps -aq)

现在开始做镜像迁移的工作
查看镜像

[root@localhost kodbox]# docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
kodcloud/kodbox   latest    58cb616b43ad   7 hours ago    405MB
mariadb           10.6      d7a7b84914e9   2 months ago   396MB
redis             alpine    435993df2c8d   4 months ago   41MB

打包镜像

[root@localhost kodbox]# docker save kodcloud/kodbox -o kodcloud.tar.gz
[root@localhost kodbox]# docker save mariadb -o mariadb.tar.gz
[root@localhost kodbox]# docker save redis -o redis.tar
[root@localhost kodbox]# ls
db  db.env  docker-compose.yml  etc  kodcloud.tar.gz  mariadb.tar.gz  redis.tar  site

通过终端将上面三个tar包下载到电脑上

2、Alpine-termux APP环境(容器加载与启用)

这时候就可以回到Alpine-termux APP了。
在Alpine-termux APP终端界面,也就是在电脑上远程访问的Alpine-termux APP的终端。
将刚刚下载的三个tar包上传到/mnt/shared/kodbox目录,没有kodbox目录就创建一个。

上传完毕,就可以将三个tar包加载到Alpine-termux虚拟机的Docker中了。
加载比较慢,准备好小风扇和耐心,小风扇用来给手机降温,耐心就是起来喝杯水,活动活动!
20分钟以内可以load完毕,具体看你的手机性能。

root@alpine-term /mnt/shared/kodbox/kodbox # ls
kodcloud.tar.gz  mariadb.tar.gz  redis.tar
root@alpine-term /mnt/shared/kodbox/kodbox # docker load -i kodcloud.tar.gz
0d132584d8c5: Loading layer [==================================================>]  4.608kB/4.608kB
624532f7ccc6: Loading layer [==================================================>]  16.64MB/16.64MB
db5380e6eb60: Loading layer [==================================================>]  29.18kB/29.18kB
5aac726471b9: Loading layer [==================================================>]  117.7MB/117.7MB
d232fe2802e2: Loading layer [==================================================>]  11.78kB/11.78kB
Loaded image: kodcloud/kodbox:latest
root@alpine-term /mnt/shared/kodbox/kodbox # docker load -i mariadb.tar.gz
4a1518ebc26e: Loading layer [==================================================>]  75.19MB/75.19MB
83f847955cac: Loading layer [==================================================>]  337.9kB/337.9kB
9fdf21bd2866: Loading layer [==================================================>]  19.82MB/19.82MB
5e288c3023fb: Loading layer [==================================================>]  1.536kB/1.536kB
cec328595a1a: Loading layer [==================================================>]   5.12kB/5.12kB
4f0916a5998c: Loading layer [==================================================>]  306.7MB/306.7MB
dc6ebc95f266: Loading layer [==================================================>]   12.8kB/12.8kB
d5edc3bae6d4: Loading layer [==================================================>]  29.18kB/29.18kB
Loaded image: mariadb:10.6
root@alpine-term /mnt/shared/kodbox/kodbox # docker load -i redis.tar
cc28a282a293: Loading layer [==================================================>]  11.78kB/11.78kB
4afac1336e0b: Loading layer [==================================================>]  1.986MB/1.986MB
442071c42c46: Loading layer [==================================================>]  2.445MB/2.445MB
ea9ee74b2076: Loading layer [==================================================>]  30.08MB/30.08MB
fdb08b0a99f7: Loading layer [==================================================>]  1.536kB/1.536kB
5f70bf18a086: Loading layer [==================================================>]  1.024kB/1.024kB
575a330fe53e: Loading layer [==================================================>]  4.096kB/4.096kB
Loaded image: redis:alpine

加载完镜像后,查看docker镜像。
完美,镜像已经成功导入docker了。

root@alpine-term /mnt/shared/kodbox/kodbox # docker images
REPOSITORY        TAG       IMAGE ID       CREATED        SIZE
kodcloud/kodbox   latest    58cb616b43ad   8 hours ago    405MB
mariadb           10.6      d7a7b84914e9   2 months ago   396MB
redis             alpine    435993df2c8d   4 months ago   41MB

现在还不能立马启动镜像,因为/mnt/shared目录虽然空间大,但是它本身是手机的系统目录,所以这里会有权限问题。
这个/mnt/shared目录导致的权限问题会让mariadb容器无法find /var/lib/mysql目录。
所以/mnt/shared目录也就是临时用来存放一下较大的镜像。
在我之前的实验中mariadb容器就报出了find: ‘/var/lib/mysql/’: Operation not permitted的问题!

root@alpine-term /mnt/shared/kodbox # docker logs -f --tail 500 5286394745f4
2024-05-11 03:55:19+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.17+maria~ubu2004 started.
find:/var/lib/mysql/: Operation not permitted

所以这里不能在/mnt/shared目录创建docker-compose.yml文件。
回到home目录,在home目录下创建kodbox目录。
这里执行部分之前在centos7虚拟机中的操作步骤。
创建db.env文件

vim db.env

写入内容

MYSQL_PASSWORD=test@123
MYSQL_DATABASE=kodbox
MYSQL_USER=kodbox

创建docker-compose.yml 文件,在其中配置映射端口、持久化目录

vim docker-compose.yml

配置文件里的volumes参数路径要修改,不要是/mnt/shared目录就好。

version: '3.5'

services:
  db:
    image: mariadb:10.6
    restart: always
    command: --transaction-isolation=READ-COMMITTED --log-bin=binlog --binlog-format=ROW
    volumes:
      - "/root/kodbox/db:/var/lib/mysql"       #./db是数据库持久化目录,可以修改
      # - "./etc/mysql/conf.d:/etc/mysql/conf.d"       #增加自定义mysql配置
    environment:
      - MYSQL_ROOT_PASSWORD=test@123
      - MARIADB_AUTO_UPGRADE=1
      - MARIADB_DISABLE_UPGRADE_BACKUP=1
    env_file:
      - db.env
      
  app:
    image: kodcloud/kodbox
    restart: always
    ports:
      - 8088:80                       #左边8088是使用端口,可以修改
    volumes:
      - "/root/kodbox/site:/var/www/html"      #./site是站点目录位置,可以修改
    environment:
      - MYSQL_HOST=db
      - REDIS_HOST=redis
    env_file:
      - db.env
    depends_on:
      - db
      - redis

  redis:
    image: redis:alpine
    restart: always

增加自定义mysql配置,在/root/kodbox目录下

mkdir -p ./etc/mysql/conf.d && vim ./etc/mysql/conf.d/custom.cnf

好了!万事俱备只欠东风,现在可以运行容器了,在/root/kodbox目录下执行docker-compose命令

root@alpine-term ~/kodbox # docker-compose up -d
[+] Running 3/3
 ✔ Container kodbox-redis-1  Started         
 ✔ Container kodbox-db-1     Started           
 ✔ Container kodbox-app-1    Started 

容器启动成功后,查看容器的运行状态,一切正常。

root@alpine-term ~/kodbox # docker ps
CONTAINER ID   IMAGE             COMMAND                  CREATED         STATUS              PORTS                                     NAMES
eb836231f104   kodcloud/kodbox   "/entrypoint.sh supe…"   5 minutes ago   Up About a minute   443/tcp, 9000/tcp, 0.0.0.0:8088->80/tcp   kodbox-app-1
7eae29c2919e   redis:alpine      "docker-entrypoint.s…"   5 minutes ago   Up 3 minutes        6379/tcp                                  kodbox-redis-1
ef60633e2ead   mariadb:10.6      "docker-entrypoint.s…"   5 minutes ago   Up 3 minutes        3306/tcp                                  kodbox-db-1

但是此时还不能确定真的一切正常,我们需要确定之前的因目录权限问题导致的mariadb数据库容器报错find: ‘/var/lib/mysql/’: Operation not permitted的问题还有没有!
查看mariadb数据库容器日志

docker logs -f --tail 500 ef60633e2ead

日志

db-1  | 2024-05-11 04:58:10+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.17+maria~ubu2004 started.
db-1  | 2024-05-11 04:58:15+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db-1  | 2024-05-11 04:58:15+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:10.6.17+maria~ubu2004 started.
db-1  | 2024-05-11 04:58:19+00:00 [Note] [Entrypoint]: Initializing database files
db-1  |
db-1  |
db-1  | PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
db-1  | To do so, start the server, then issue the following command:
db-1  |
db-1  | '/usr/bin/mariadb-secure-installation'
db-1  |
db-1  | which will also give you the option of removing the test
db-1  | databases and anonymous user created by default.  This is
db-1  | strongly recommended for production servers.
db-1  |
db-1  | See the MariaDB Knowledgebase at https://mariadb.com/kb
db-1  |
db-1  | Please report any problems at https://mariadb.org/jira
db-1  |
db-1  | The latest information about MariaDB is available at https://mariadb.org/.
db-1  |
db-1  | Consider joining MariaDB's strong and vibrant community:
db-1  | https://mariadb.org/get-involved/
db-1  |
db-1  | 2024-05-11 04:58:43+00:00 [Note] [Entrypoint]: Database files initialized
db-1  | 2024-05-11 04:58:43+00:00 [Note] [Entrypoint]: Starting temporary server
db-1  | 2024-05-11 04:58:43+00:00 [Note] [Entrypoint]: Waiting for server startup
db-1  | 2024-05-11  4:58:44 0 [Note] Starting MariaDB 10.6.17-MariaDB-1:10.6.17+maria~ubu2004-log source revision 15c75ad083a55e198ae78324f22970694b72f22b as process 95
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Number of pools: 1
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
db-1  | 2024-05-11  4:58:45 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Using Linux native AIO
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
db-1  | 2024-05-11  4:58:45 0 [Note] InnoDB: Completed initialization of buffer pool
db-1  | 2024-05-11  4:58:46 0 [Note] InnoDB: 128 rollback segments are active.
db-1  | 2024-05-11  4:58:46 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db-1  | 2024-05-11  4:58:46 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db-1  | 2024-05-11  4:58:46 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db-1  | 2024-05-11  4:58:46 0 [Note] InnoDB: 10.6.17 started; log sequence number 42486; transaction id 14
db-1  | 2024-05-11  4:58:46 0 [Note] Plugin 'FEEDBACK' is disabled.
db-1  | 2024-05-11  4:58:46 0 [Warning] 'user' entry 'root@46f814c57da6' ignored in --skip-name-resolve mode.
db-1  | 2024-05-11  4:58:47 0 [Warning] 'proxies_priv' entry '@% root@46f814c57da6' ignored in --skip-name-resolve mode.
db-1  | 2024-05-11  4:58:47 0 [Note] mariadbd: ready for connections.
db-1  | Version: '10.6.17-MariaDB-1:10.6.17+maria~ubu2004-log'  socket: '/run/mysqld/mysqld.sock'  port: 0  mariadb.org binary distribution
db-1  | 2024-05-11 04:58:47+00:00 [Note] [Entrypoint]: Temporary server started.
db-1  | 2024-05-11 05:00:21+00:00 [Note] [Entrypoint]: Creating database kodbox
db-1  | 2024-05-11 05:00:21+00:00 [Note] [Entrypoint]: Creating user kodbox
db-1  | 2024-05-11 05:00:21+00:00 [Note] [Entrypoint]: Giving user kodbox access to schema kodbox
db-1  | 2024-05-11 05:00:21+00:00 [Note] [Entrypoint]: Securing system users (equivalent to running mysql_secure_installation)
db-1  |
db-1  | 2024-05-11 05:00:22+00:00 [Note] [Entrypoint]: Stopping temporary server
db-1  | 2024-05-11  5:00:22 0 [Note] mariadbd (initiated by: unknown): Normal shutdown
db-1  | 2024-05-11  5:00:22 0 [Note] InnoDB: FTS optimize thread exiting.
db-1  | 2024-05-11  5:00:23 0 [Note] InnoDB: Starting shutdown...
db-1  | 2024-05-11  5:00:23 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
db-1  | 2024-05-11  5:00:23 0 [Note] InnoDB: Buffer pool(s) dump completed at 240511  5:00:23
db-1  | 2024-05-11  5:00:23 0 [Note] InnoDB: Removed temporary tablespace data file: "./ibtmp1"
db-1  | 2024-05-11  5:00:23 0 [Note] InnoDB: Shutdown completed; log sequence number 42514; transaction id 15
db-1  | 2024-05-11  5:00:23 0 [Note] mariadbd: Shutdown complete
db-1  |
db-1  | 2024-05-11 05:00:23+00:00 [Note] [Entrypoint]: Temporary server stopped
db-1  |
db-1  | 2024-05-11 05:00:23+00:00 [Note] [Entrypoint]: MariaDB init process done. Ready for start up.
db-1  |
db-1  | 2024-05-11  5:00:24 0 [Note] Starting MariaDB 10.6.17-MariaDB-1:10.6.17+maria~ubu2004-log source revision 15c75ad083a55e198ae78324f22970694b72f22b as process 1
db-1  | 2024-05-11  5:00:25 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db-1  | 2024-05-11  5:00:25 0 [Note] InnoDB: Number of pools: 1
db-1  | 2024-05-11  5:00:25 0 [Note] InnoDB: Using crc32 + pclmulqdq instructions
db-1  | 2024-05-11  5:00:25 0 [Note] mariadbd: O_TMPFILE is not supported on /tmp (disabling future attempts)
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: Using Linux native AIO
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: Initializing buffer pool, total size = 134217728, chunk size = 134217728
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: Completed initialization of buffer pool
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: 128 rollback segments are active.
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db-1  | 2024-05-11  5:00:26 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db-1  | 2024-05-11  5:00:27 0 [Note] InnoDB: 10.6.17 started; log sequence number 42514; transaction id 14
db-1  | 2024-05-11  5:00:27 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db-1  | 2024-05-11  5:00:27 0 [Note] Plugin 'FEEDBACK' is disabled.
db-1  | 2024-05-11  5:00:27 0 [Note] InnoDB: Buffer pool(s) load completed at 240511  5:00:27
db-1  | 2024-05-11  5:00:27 0 [Note] Server socket created on IP: '0.0.0.0'.
db-1  | 2024-05-11  5:00:27 0 [Note] Server socket created on IP: '::'.

容器正常了!

3、端口映射

正常来说此时可以通过http://IP:8088访问页面。
但是由于Alpine-termux是termux中的虚拟机,所以现在和之前映射22端口的逻辑是一致的,想在局域网其它电脑访问,还需要一步端口映射的步骤。

手指在Alpine-termux APP软件的左上方向右滑动,调出菜单。
选择[1]QEMU
映射docker-compose.yml文件中的8088端口到手机的8088端口,
输入

hostfwd_add tcp::8088-:8088

无报错即映射成功。

确保手机和电脑端在同一局域网,在电脑上访问手机IP+8088端口:http://172.16.12.21:8088
即可进入可道云盘系统页面。

4、注意事项

使用df -h命令查看Alpine-termux虚拟机磁盘使用情况:

root@alpine-term ~/kodbox # df -h
Filesystem      Size  Used Avail Use% Mounted on
devtmpfs         10M     0   10M   0% /dev
shm             1.2G     0  1.2G   0% /dev/shm
/dev/sda1       3.9G  3.1G  814M  80% /
tmpfs           238M  392K  238M   1% /run
shared_storage  111G   55G   56G  50% /mnt/shared
cgroup_root      10M     0   10M   0% /sys/fs/cgroup
overlay         3.9G  3.1G  814M  80% /var/lib/docker/overlay2/445d015b44d1cb7d2142cabbfeb79af5b9e47f7e64ced98cfe8f1951e3daae99/merged
overlay         3.9G  3.1G  814M  80% /var/lib/docker/overlay2/bca102fa6d64d9f6bee6643d5c1bc6a8aaef84dd6027cca96768a9814c282e32/merged
overlay         3.9G  3.1G  814M  80% /var/lib/docker/overlay2/371d5dda407fb0dc82b66e577e44e6a4f1f60ab81cbde43181533de1ebe34b7c/merged

这里看见/mnt/shared 的容量是最大的。
但是这个问题前面也说了,因为/mnt/shared是手机目录的原因,所以我们在这个目录下的操作有些寸步难行,因为权限问题嘛。
也导致虽然云盘部署完成了,但是其它目录太小,数据库也会有持久化,没有足够空间存放资料的难题。

所以这个问题,需要我们在手机上新增一张sd存储卡。
或者使用OTG外接硬盘,但是这个也具体看手机是否支持,这个可以咨询手机官方。

外接存储方案实现后,需要在Alpine-termux虚拟机里将外接的磁盘挂载到Alpine-termux虚拟机系统。

全篇完!

参考资料

感谢!

  • Android运行Docker!(Termux + QEMU + linux_alpine, qemu网络映射)
    https://stageguard.top/2019/08/15/run-docker-on-qemu-alpine/#1-Docker
  • 安卓手机无需root使用Alpine Term APK安装Linux系统,并安装docker+青龙面板
    https://zhuanlan.zhihu.com/p/521077807
  • AlpineTerm使用教程
    https://www.cnblogs.com/lcyc/p/18090977
  • CSDN:alpine初始化配置和踩坑记录
    https://blog.csdn.net/u012886849/article/details/128710456
  • 简书:Alpine换源解决在docker容器中,安装软件容易失败的问题
    https://www.jianshu.com/p/6398e59e538b
  • CSDN:centos7 安装docker遇到的无法启动的问题
    https://blog.csdn.net/africanviolet/article/details/134735648
  • 博客园:25-********* docker使用报错总结 ********
    https://www.cnblogs.com/robinunix/p/13746268.html

参考大模型

感谢!

  • 通义千问
    https://qianwen.aliyun.com/?spm=5176.28326591.0.0.40f713f41IAvwM
  • Kimi
    https://kimi.moonshot.cn/chat/cnsj7umcp7fct1jqe3r
  • GPT3.5_16k
    https://www.zaiwen.top/chat/working-edition

镜像站使用

感谢!

  • 阿里云:阿里巴巴开源镜像站
    https://mirrors.aliyun.com
  • USTC:中国科学技术大学开源软件镜像站
    http://mirrors.ustc.edu.cn/alpine/v3.13/
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐