Files
oneclickvirt.github.io/docs/guide/docker/docker_build.md
spiritlhl d3d7587876 update
2024-01-15 13:16:41 +00:00

164 lines
4.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
---
outline: deep
---
# 前言
两种开设方式
## 单独开设
- 只生成一个docker这里有判断为国际服务器还是国内服务器如果在国内服务器上开设容器内的包管理源自动替换为清华源
- 可配置绑定独立的IPV6地址但需要先前使用本套脚本的环境安装命令安装的docker且需要宿主机至少绑定了/112的IPV6子网
- 支持x86_64和ARM架构的服务器
### 下载脚本
国际
```shell
curl -L https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/onedocker.sh -o onedocker.sh && chmod +x onedocker.sh
```
国内
```shell
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/onedocker.sh -o onedocker.sh && chmod +x onedocker.sh
```
### 示例
运行支持的变量
```
./onedocker.sh name cpu memory password sshport startport endport <independent_ipv6> <system>
```
目前system仅支持选择
- alpine
- debian
- ubuntu
- almalinux
默认不填则是debian
```shell
./onedocker.sh test 1 512 123456 25000 34975 35000 N debian
```
以下为开设的示例容器的信息:
| 属性 | 值 |
|------------------------|----------------|
| 容器名字 | test |
| SSH登录的用户名 | root |
| SSH登录的密码 | 123456 |
| CPU核数 | 1 |
| 内存大小 | 512MB |
| SSH端口 | 25000 |
| 内外网映射端口一致的区间 | 34975到35000 |
| 系统 | debian |
| 是否绑定独立的IPV6地址 | N |
### 相关操作
删除示例
```shell
docker rm -f test
rm -rf test
ls
```
进入示例
```shell
docker exec -it test /bin/bash
```
要退出容器就执行```exit```退出。
查询已开设的信息
```shell
cat 容器名字
```
输出格式
```
容器名字 SSH端口 登陆的root密码 核数 内存 外网端口起 外网端口止
```
docker的ipv6地址只能在容器内自己查询在docker的配置中是不存在的
## 批量开设
- 批量多次运行继承配置生成
- 生成多个时为避免SSH连接中断建议在screen中执行
- 支持x86_64和ARM架构的服务器
### 运行
国际
```shell
curl -L https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/create_docker.sh -o create_docker.sh && chmod +x create_docker.sh && bash create_docker.sh
```
国内
```shell
curl -L https://cdn.spiritlhl.net/https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/onedocker.sh -o onedocker.sh && chmod +x onedocker.sh
```
### 查询批量开设的信息
```shell
cat dclog
```
输出格式
```
容器名字 SSH端口 登陆的root密码 核数 内存 外网端口起 外网端口止
```
一行一个容器对应的信息docker的ipv6地址只能在容器内自己查询在docker的配置中是不存在的
## 卸载所有docker容器和镜像
以下命令卸载会忽略ndpresponder以防止IPV6的配置失效
```shell
docker ps -aq --format '{{.Names}}' | grep -E '^ndpresponder' | xargs -r docker rm -f
docker images -aq --format '{{.Repository}}:{{.Tag}}' | grep -E '^ndpresponder' | xargs -r docker rmi
rm -rf dclog
ls
```
## 更新上述所有脚本
删除原始配置脚本
```bash
rm -rf /usr/local/bin/ssh_sh.sh
rm -rf /usr/local/bin/ssh_bash.sh
rm -rf /usr/local/bin/check-dns.sh
rm -rf /root/ssh_sh.sh
rm -rf /root/ssh_bash.sh
rm -rf /root/onedocker.sh
rm -rf /root/create_docker.sh
```
下载回新版本的相关配置脚本
```bash
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/extra_scripts/check-dns.sh -O /usr/local/bin/check-dns.sh && chmod +x /usr/local/bin/check-dns.sh
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/config.sh -O /usr/local/bin/config.sh && chmod +x /usr/local/bin/config.sh
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/ssh_bash.sh -O /usr/local/bin/ssh_bash.sh && chmod +x /usr/local/bin/ssh_bash.sh
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/ssh_sh.sh -O /usr/local/bin/ssh_sh.sh && chmod +x /usr/local/bin/ssh_sh.sh
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/onedocker.sh -O /root/onedocker.sh && chmod +x /root/onedocker.sh
wget https://raw.githubusercontent.com/spiritLHLS/docker/main/scripts/create_docker.sh -O /root/create_docker.sh && chmod +x /root/create_docker.sh
```