docker使用

使用docker compose

容器互访

# 创建一个用于互相访问的网络
docker network create free
# 绑定到网络
docker network connect free ${CONTAINER_NAME}

初始化脚本

# 容器创建后会自动执行/docker-entrypoint-initdb.d目录下的.sh .sql .sql.gz文件。
# 示例 初始化nacos_config数据库
# 下载对应版本的sql文件放在docker-entrypoint-initdb.d
# 编辑sql在最前边加上三行
SET NAMES utf8mb4; # 避免乱码
CREATE DATABASE nacos_config;
USE nacos_config;
# 启动容器

查看容器IP

docker inspect --format='{{.Name}}  {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -q) | cut -d'/' -f2

ghcr.io镜像加速

南京大学镜像

docker pull ghcr.nju.edu.cn/graalvm/graalvm-ce:22.3.1

镜像下载

arm镜像需添加参数 --platform=arm64

docker pull eclipse-temurin:8-jdk
docker save --output eclipse-temurin_8-jdk_amd64.tar eclipse-temurin:8-jdk
# 从本地加载
docker load --input eclipse-temurin_8-jdk_amd64.tar
# 批量加载
for img in *.tar; do docker load -i "$img"; echo "Loaded $img"; done

运行其他架构的docker镜像

参考

portainer

docker run -d --name portainer \
--restart=always \
-p 9443:9443 \
--network free \
-e AGENT_SECRET=portainer-agent \
-m 64m \
-v /etc/localtime:/etc/localtime \
-v /var/run/docker.sock:/var/run/docker.sock:ro \
-v $(pwd)/data:/data \
portainer/portainer-ce:alpine

portainer-agent

docker官方的远程tcp连接需要配置tls等,比较麻烦,使用agent仅需配置一个密码即可。

docker run -d --name portainer-agent \
--restart=always \
-p 9001:9001 \
-e AGENT_SECRET=portainer-agent \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /var/lib/docker/volumes:/var/lib/docker/volumes \
-m 64m \
portainer/agent

mysql

创建默认配置,修改socket路径,方便mycli使用。

从8.0.29开始 _/mysql镜像支持arm64,建议选用。更低版本可选 mysql/mysql-server。
创建容器

docker run -d --name mysql \
--restart=always \
-p 3306:3306 \
-e MYSQL_ROOT_PASSWORD=123456 \
-e TZ=Asia/Shanghai \
--network free \
-v $(pwd)/etc/my.cnf:/etc/my.cnf:rw \
-v $(pwd)/var_lib_mysql:/var/lib/mysql \
mysql:8.0 \
--character-set-server=utf8mb4 \
--collation-server=utf8mb4_unicode_ci

允许socket连接(mycli默认连接方式)。

# 如果主机有安装 mysql,不能执行,会覆盖主机的 mysql socket。
# mycli貌似有bug,映射出来连接时报错,只能使用127.0.0.1连接。
docker exec mysql sed -i "s@/var/run/mysqld/mysqld.sock@/var/lib/mysql/mysql.sock@g" etc/my.cnf
docker restart mysql
sudo mkdir /var/run/mysqld/
sudo ln -s  $(pwd)/var_lib_mysql/mysql.sock /var/run/mysqld/mysqld.sock

允许远程访问(_/mysql默认即可远程连接,无需配置)

docker exec -it mysql mysql -uroot -p
use mysql;update user set host = '%' where user = 'root';FLUSH PRIVILEGES;
#GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION;   # 授权
#GRANT ALL PRIVILEGES ON test.* to 'test'@'%';     # 如果账号为“test”时,使用该命令

postgres

docker run -d --name postgres \
-p 5432:5432 \
-e POSTGRES_PASSWORD=123456 \
-e TZ=Asia/Shanghai \
--network free \
-v $(pwd)/var_lib_postgresql_data:/var/lib/postgresql/data \
postgres:alpine

oceanbase

# 此处配置为单机版 最低剩余内存需大于4G 安装后CPU占用很高
# 默认密码为空
docker run -d --name obstandalone \
-p 2881:2881 \
-e TZ=Asia/Shanghai \
-e OB_ROOT_PASSWORD=123456 \
-e MINI_MODE=1 \
-v $(pwd)/ob:/root/ob \
-v $(pwd)/obd:/root/.obd \
--network free \
oceanbase/oceanbase-ce:4.1.0.0

redis

docker run -d --name redis \
--restart=always \
-p 6379:6379 \
-e TZ=Asia/Shanghai \
--network free \
-m 256m \
-v $(pwd)/data:/data \
redis:7.0 \
--appendonly yes \
--requirepass "123456"

mongo

docker run -d --name mongo \
--restart=always \
-p 27017:27017 \
-e MONGO_INITDB_ROOT_USERNAME=admin \
-e MONGO_INITDB_ROOT_PASSWORD=123456 \
-e TZ=Asia/Shanghai \
--network free \
-m 512m \
-v $(pwd)/data_db:/data/db \
-v $(pwd)/data_configdb:/data/configdb \
mongo:7.0 --auth

创建用户

use admin
db.auth("admin","123456")
use learn
db.createUser({user:'root',pwd:'123456',roles:[{role:'dbOwner',db:'learn'}]})
db.createCollection("test")

nacos

不使用外部数据库

docker run -d --name nacos \
--restart=always \
--network free \
-p 8848:8848 \
-p 9848:9848 \
-v $(pwd)/home_nacos_data:/home/nacos/data \
-e MODE=standalone \
-e NACOS_AUTH_ENABLE=true \
-e NACOS_AUTH_IDENTITY_KEY=serverIdentity \
-e NACOS_AUTH_IDENTITY_VALUE=security \
-e NACOS_AUTH_TOKEN=SecretKEY012345678901234567890123456789012345678901234567890123456789 \
-e LOGGING_LEVEL_ROOT=OFF \
-m 1024m \
nacos/nacos-server:v2.4.2.1-slim

调整服务端日志级别,避免过多磁盘占用。
官方文档
默认日志配置中允许的日志文件总大小最大152G。/home/nacos/conf/nacos-logback.xml
生产环境请适当做调整。

# 调整naming模块的naming-raft.log的级别为info:
curl -X PUT 'localhost:8848/nacos/v1/ns/operator/log?logName=naming-raft&logLevel=err'
# 调整config模块的config-dump.log的级别为info:
curl -X PUT 'localhost:8848/nacos/v1/cs/ops/log?logName=config-dump&logLevel=err'
# 查看是否开启权限
curl -X GET 'http://127.0.0.1:8848/nacos/v1/cs/configs?dataId=demo.yml&group=DEFAULT_GROUP'

单机版内置数据在512M下即可运行(jdk替换为ibm-semeru-runtimes:open-8-jdk内存占用可继续压缩,但CPU占用会上升)

-e JVM_XMS="512m" \
-e JVM_XMX="512m" \
-e JVM_XMN="256m" \
-e JVM_MS="64m" \
-e JVM_MMS="160m" \
-m 512m \

使用数据库,此处使用上文创建的mysql容器持久化,需要先创建数据库nacos_config,并执行初始化脚本。
注意不同版本sql可能不一样,此处为2.2.3版本。
脚本链接
在wsl中用docker安装的mysql,开机后需要被连接一下(唤醒???),nacos才能连接成功,否则一直报错No DataSource set

rnacos

使用rust实现,兼容nacos的SDK,只具备基础功能,占用资源很少。

docker run -d --name rnacos \
-p 8848:8848 \
-p 9848:9848 \
-v $(pwd)/io:/io \
-m 32m \
qingpan/rnacos

rocketmq

docker run -d --name mqnamesrv \
--network free \
-p 9876:9876 \
-e TZ=Asia/Shanghai \
-e "JAVA_OPT_EXT=-server -Xms256m -Xmx256m -Xmn256m" \
-v $(pwd)/rocketmq/namesrv_root_logs:/root/logs \
-v $(pwd)/rocketmq/namesrv_root_store:/root/store \
-m 512m \
apache/rocketmq:5.1.3 ./mqnamesrv

broker要求至少4G空间才能正常工作
挂载目录会报错,待测试
-v $(pwd)/home_rocketmq_store:/home/rocketmq/store \

设置../conf/broker.conf中追加broker的IP配置 ,WSL下设置为127.0.0.1,其他则设为外网IP,否则docker下注册的IP可能有问题。

brokerIP1=127.0.0.1
docker run -d --name mqbroker \
--network free \
-p 10909:10909 \
-p 10911:10911 \
-p 10912:10912 \
-e TZ=Asia/Shanghai \
-e "JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn256m" \
-v $(pwd)/rocketmq/broker_root_logs:/root/logs \
-v $(pwd)/rocketmq/broker_root_store:/root/store \
-m 1024m \
apache/rocketmq:5.1.3 ./mqbroker -c ../conf/broker.conf -n mqnamesrv:9876

rocketmq-dashboard

docker run -d --name rocketmq-dashboard \
--network free \
-p 9877:8080 \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=mqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-m 1024m \
apacherocketmq/rocketmq-dashboard

seata

docker run -d --name seata \
-p 7091:7091 \
-p 8091:8091 \
-e TZ=Asia/Shanghai \
--network free \
-m 1024m \
-v $(pwd)/application.yml:/seata-server/resources/application.yml \
seataio/seata-server:1.7.0

复制一份默认配置

docker cp seata:/seata-server/resources/application.yml .

修改application.yml,以nacos为注册中心。

seata:
  registry:
    type: nacos
    preferred-networks: 192.168.*
    nacos:
      application: seata-server
      server-addr: nacos:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos

alpine

apk换国内源

sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
docker run -d -it --name alpine \
-e TZ=Asia/Shanghai \
--network free \
alpine:3

busybox

docker run -d -it --name busybox \
-e TZ=Asia/Shanghai \
--network free \
busybox:stable

registry

docker run -d --name registry \
-p 5000:5000 \
-e TZ=Asia/Shanghai \
--network free \
-v $(pwd)/var_lib_registry:/var/lib/registry \
registry:2.8

firefox

nginx代理
挂载雅黑字体到容器,避免中文乱码。

if [ ! -e msyh ];then mkdir msyh;fi
ls /mnt/c/Windows/Fonts/msy*.ttc | xargs -i cp -n {} msyh
docker run -d --name=firefox \
-p 5800:5800 \
--network free \
-e VNC_PASSWORD=123456 \
-e LANG=zh_CN.UTF-8 \
-e TZ=Asia/Shanghai \
-v $(pwd)/config:/config \
-v $(pwd)/msyh:/usr/share/fonts/msyh \
-m 1024m \
jlesage/firefox

ttyd

终端分享到web
官网

docker run -d --name ttyd \
-p 7681:7681 \
--network free \
tsl0922/ttyd

easyconnect

网络原因镜像拉不下来,借助下方的工具。

wget https://ghproxy.com/https://github.com/blacktop/graboid/releases/download/0.15.8/graboid_0.15.8_linux_x86_64.tar.gz
tar -xvf graboid_0.15.8_linux_x86_64.tar.gz
./graboid hagb/docker-easyconnect:7.6.7
docker load --input hagb_docker-easyconnect_7.6.7.tar.gz

实测账号名不能包含中文,安装了雅黑字体也不行。

docker run -td --name easyconnect \
--device /dev/net/tun \
--cap-add NET_ADMIN \
-e PASSWORD=123456 \
-v $()/ecdata:/root \
-p 127.0.0.1:5901:5901 \
-p 127.0.0.1:1080:1080 \
-p 127.0.0.1:8888:8888 \
hagb/docker-easyconnect:7.6.7

kms

docker run -d --name py-kms \
--restart always \
-p 1688:1688 \
-v /etc/localtime:/etc/localtime:ro \
ghcr.io/py-kms-organization/py-kms

watchtower

docker run -d --name watchtower \
-v /var/run/docker.sock:/var/run/docker.sock \
containrrr/watchtower

更新指定容器,不指定容器名则更新所有。

docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -c -R  redis

alist

官方文档

docker run -d --name alist  \
--restart=always \
-p 5244:5244 \
-e TZ=Asia/Shanghai \
-e PUID=$(id -u) \
-e PGID=$(id -g) \
-e UMASK=022 \
-e ALIST_ADMIN_PASSWORD="alist123." \
-m 64m \
--network free \
-v $(pwd)/opt_alist_data:/opt/alist/data \
-v $(pwd)/opt_alist_local:/opt/alist/local \
xhofe/alist
# 未设置默认密码时,查看默认用户admin的密码。
docker exec -it alist ./alist admin
# 修改路径到 /alist 用于nginx反向代理 重启生效
docker exec -it alist  sed -i 's@"site_url": ""@"site_url": "/alist"@g' /opt/alist/data/config.json

syncthing

docker run -d \
--name syncthing \
--restart unless-stopped \
-e TZ=Asia/Shanghai \
-e PUID=$(id -u) \
-e PGID=$(id -g) \
-e UMASK=022 \
-v $(pwd)/var_syncthing:/var/syncthing \
--network="host" \
--memory=128m \
syncthing/syncthing

smartdns

docker run -d --name smartdns \
--restart=always \
-e TZ=Asia/Shanghai \
-p 53:53/udp \
-m 16m \
0x5826/smartdns

frp

docker run -di --name=frpc \
--restart=always \
-e NATFRP_TARGET=xxx \
-e NATFRP_TOKEN=xxx \
-m 32m \
natfrp/frpc

cpolar

后台地址

docker run -di --name cpolar \
-p 9200:9200 \
probezy/cpolar

cloudflared

docker run --name cloudflared \
--restart=always \
-v $(pwd)/etc_cloudflared:/etc/cloudflared \
-m 32m \
cloudflare/cloudflared tunnel run

把密钥文件tunnelID-xxx.json和配置文件config.yml放在etc_cloudflared目录下,便于挂载。
此处的文件是通过命令行创建隧道得到的,命令行创建不需要添加付款信息。参见官网

config.yml

# @see https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/install-and-setup/tunnel-guide/local/local-management/ingress/
# 验证配置文件
# docker exec -it cloudflared cloudflared tunnel ingress validate
# vue项目 invalid host header
# @see https://blog.csdn.net/luxiahongyi/article/details/123489141
tunnel: tunnelID-xxx
credentials-file: /etc/cloudflared/tunnelID-xxx.json

ingress:
  - hostname: test.example.com
    path: /demo/*
    service: http://172.17.0.1:8081

  - hostname: test.example.com
    service: http://172.17.0.1:8082

  - service: http_status:404

ipfs

浏览器扩展
Chrome
Firefox

docker run -d --name ipfs \
--restart=always \
-m 256m \
-p 4001:4001 \
-p 4001:4001/udp \
-p 127.0.0.1:9080:8080 \
-p 127.0.0.1:5001:5001 \
-v $(pwd)/export:/export \
-v $(pwd)/data_ipfs:/data/ipfs \
ipfs/kubo

修改端口(默认8080)

docker exec -it ipfs ipfs config Addresses.Gateway /ip4/127.0.0.1/tcp/9080

切换默认配置
lowpower 适合个人电脑,占用低。
server 适合服务器,会关闭一些无用服务。

docker exec -it ipfs ipfs config profile apply lowpower

管理页面
http://127.0.0.1:5001/webui/

github-runner

docker run -d --name github-runner \
--restart=always \
-e TZ=Asia/Shanghai \
-e RUNNER_NAME="tencent" \
-e REPO_URL="https://github.com/xxx/xxx" \
-e RUNNER_TOKEN="xxx" \
myoung34/github-runner:ubuntu-focal

kylinos

docker run -d -it --name kylinos1 \
-p 1022:22 \
-v $(pwd)/data:/data \
--memory 1024m \
kylinos:v10sp1

kylin_aarch64.repo

[ks10-adv-os]
name = Kylin Linux Advanced Server 10 - Os
baseurl = http://archive2.kylinos.cn/rpm/kylin/production/KY-KY10-GFB-aarch64/custom/kylin-server/KY10-GFB-aarch64/
#baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1/os/adv/lic/base/$basearch/
gpgcheck = 0
enabled = 1

[ks10-adv-updates]
name = Kylin Linux Advanced Server 10 - Updates
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1/os/adv/lic/updates/$basearch/
gpgcheck = 0
enabled = 0

[ks10-adv-addons]
name = Kylin Linux Advanced Server 10 - Addons
baseurl = http://update.cs2c.com.cn:8080/NS/V10/V10SP1/os/adv/lic/addons/$basearch/
gpgcheck = 0
enabled = 0

.bashrc

alias ls='ls --color=auto'
alias dir='dir --color=auto'
alias vdir='vdir --color=auto'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias cls='printf "\033c"'

Dockerfile

FROM zuoguochen/kylinos:v10sp1

# 将当前目录下的kylin_aarch64.repo复制到/etc/yum.repos.d
COPY kylin_aarch64.repo /etc/yum.repos.d/
COPY .bashrc /root/.bashrc

ENTRYPOINT ["/usr/bin/bash"]

unit

配置变为json,使用rest接口修改,能自动更新。
没找到原本的转发怎么配置。如443/AAA -> 8082/BBB/,只能443/AAA -> 8082/AAA/

docker run -d --name unit \
-p 80:80 \
-m 32m \
--network free \
unit

查看配置

curl --unix-socket /var/run/control.unit.sock http://localhost/config

开启log

curl -X PUT -d '"/var/log/access.log"' --unix-socket /var/run/control.unit.sock http://localhost/config/access_log

添加一条转发(配置是按从前往后匹配的,直接添加会在默认配置最后一个,匹配不到)
这里转发目标不能带路径,只能使用IP。

cat << EOF > config.json
{
    "match": {
        "uri": "/nacos/*"
    },
    "action": {
        "proxy": "http://192.168.1.xx:8848"
    }
}
EOF
curl -X POST --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config/routes

修改配置

curl -X PUT --data-binary @config.json --unix-socket /var/run/control.unit.sock http://localhost/config/routes/0

删除配置

curl -X DELETE --unix-socket /var/run/control.unit.sock http://localhost/config/routes/0

nginx

# 生成默认配置
if [ ! -e etc_nginx ];then mkdir etc_nginx;fi
docker run --name tmp-nginx-container -d nginx:alpine
docker cp tmp-nginx-container:/etc/nginx/nginx.conf $(pwd)/etc_nginx/nginx.conf
docker cp tmp-nginx-container:/etc/nginx/conf.d etc_nginx/conf.d/
docker rm -f tmp-nginx-container
# 创建容器
docker run -d --name nginx \
--restart=always \
-p 443:443 \
-e TZ=Asia/Shanghai \
-m 32m \
--network free \
-v $(pwd)/etc_nginx/conf.d:/etc/nginx/conf.d \
-v $(pwd)/etc_nginx/nginx.conf:/etc/nginx/nginx.conf:rw \
-v $(pwd)/js:/js \
nginx:alpine

nginx配置

如果nginx容器需要访问主机的端口,默认使用172.17.0.1:xxx来访问。
如自定义了网络,使用来查看docker network inspect network_name的Gateway配置。

# /etc/nginx/conf.d/default.conf
server {
    listen 80;
    server_name www.example.com;
    # 自动跳转https
    return 302 https://$host$request_uri;
}
server {
    # listen 443;
    listen 443 ssl;
    http2 on;
    server_name         www.example.com;
    ssl_certificate     www.example.com.crt;
    ssl_certificate_key www.example.com.key;
    ssl_prefer_server_ciphers  on;

    listen 443 quic reuseport;
    add_header alt-svc 'h3=":443"; ma=2592000';
    quic_retry on;
    ssl_early_data on;

    error_page 404 /404.html;

    include /etc/nginx/conf.d/sub/*.conf;

    root   /js;
    index  index.html index.htm;

    location /favicon.ico {
        alias /html/favicon.ico;
    }
    # 屏蔽static下一级二级目录中以数字开头的请求
    location ~ ^/static(/\w)?(/\d+.*)+/ {
        return 404;
    }
    location /ip {
        default_type text/plain;
        return 200 $remote_addr;
    }
    location /ip_ {
        default_type application/json;
        return 200 "{\"ip\":\"$remote_addr\"}";
    }
    location / {
        try_files $uri $uri/ break;
   }

    location /portainer/ {
        proxy_pass   https://portainer:9443/;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /nacos/ {
        proxy_pass   http://nacos:8848/nacos/;
        proxy_set_header X-Real-IP  $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
    location /alist/ {
        proxy_pass http://alist:5244/alist/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Range $http_range;
        proxy_set_header If-Range $http_if_range;
        proxy_redirect off;
        client_max_body_size 20000m;
    }
    location /firefox/ {
        proxy_pass http://firefox:5800/;
        location /firefox/websockify {
            proxy_pass http://firefox:5800/websockify/;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_read_timeout 86400;
        }
    }
}
# 端口转发
#  /etc/nginx/nginx.conf
http {

   # 隐藏nginx版本号
   server_tokens off;
   # 调整文件上传大小限制
   client_max_body_size 32m;
   # 调整请求头大小限制
   #client_header_buffer_size 512k;
   #large_client_header_buffers 4 512k;

    # 配置gzip
    gzip  on;
    gzip_vary on;
    gzip_static on;
    gzip_proxied any;
    gzip_min_length 1k;
    gzip_types text/plain application/css text/css text/javascript application/javascript application/x-javascript application/json;

}
stream {
    server {
        # docker 容器要把该端口放出来
        listen 13306;
        proxy_connect_timeout 10s;
        proxy_timeout 300s;
        proxy_pass mysql:3306;
    }
    upstream web {
     server 192.168.10.10:443;
     server 192.168.10.20:443;
     server 192.168.10.30:443;
     }
    server {
        listen 443;
        proxy_pass web:443;
    }
}

生成gzip文件

nginx静态gzip需提前生成gz文件
gzip_static生效后响应体 headers 的 ETag 没有【W/】

#!/bin/bash

# 指定文件所在目录
directory="js/"
# 排除某些格式
exclude_regex=".*\.\(mp4\|mp3\|gz\)$"

# 遍历处理
#find "$directory" -type f -size +1k -not -regex "$exclude_regex" -print0 | xargs -0 -I {} sh -c 'gzip -c -9 "{}" > "{}.gz"'

find "$directory" -type f -size +1k -not -regex "$exclude_regex" -print0 | 
while IFS= read -r -d '' file; do
    gzip -c -9 "$file" > "$file.gz"
done

安装 docker

curl -fsSL https://get.docker.com -o get-docker.sh
# WSL下会提示安装桌面版,无需理会,等几秒即可。
sudo sh ./get-docker.sh --mirror Aliyun

# 将用户加入 docker 组
sudo usermod -aG docker $USER

# docker源
sudo vim /etc/docker/daemon.json
{
  "live-restore": true,
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "100m",
    "max-file": "3"
  },
  "registry-mirrors": [
    "https://docker.m.daocloud.io",
    "https://registry.dockermirror.com",
    "https://hub-mirror.c.163.com"
  ],
  "features": {
    "buildkit": true
  },
  "experimental": true,
  "max-concurrent-uploads": 8,
  "max-concurrent-downloads": 8
}

仓库可用性检测

docker_mirror_check.sh

registries="
docker.io
dockerproxy.com
registry-1.docker.io
"
# 经常更新的镜像都可以
latest_version=$(curl -s https://mirror.ghproxy.com/https://raw.githubusercontent.com/nginxinc/docker-nginx/master/mainline/alpine-slim/Dockerfile | grep "ENV NGINX_VERSION" | cut -d' ' -f4)
image="library/nginx:${latest_version}-alpine"

for registry in $registries
do
   echo Test "${registry}/${image}"
   docker pull "${registry}/${image}" \
     && (echo -e "\033[32m$registry is good\033[0m") \
     || (echo -e "\033[31m$registry is outdated\033[0m" )
   docker rmi "${registry}/${image}" || true
done

Docker交叉打包

# 查看已有builder实例
docker buildx ls
# 待完成

查看 docker run 命令

pip install runlike
runlike xxx

End

posted @ 2021-12-07 23:58  一年`  阅读(550)  评论(0编辑  收藏  举报