Docker
容器下的 Go 应用程序优化
· ☕ 2 分钟
1. 内存对齐 结构体内字段,从大到小排列 减少内存占用 安装 fieldalignment 工具 1 go install golang.org/x/tools/go/analysis/passes/fieldalignment/cmd/fieldalignment@latest 分析并修复内存对齐 1 2 3 4 5 6 7 8 9 fieldalignment -fix ./... /Users/shaowenchen/Code/app/config/config.go:136:14: struct with 32 pointer bytes could be 24 /Users/shaowenchen/Code/app/config/config.go:150:11: struct of size 96 could be 88 /Users/shaowenchen/Code/app/config/config.go:166:14: struct of size 152 could be 144 /Users/shaowenchen/Code/app/config/config.go:194:12: struct with 80 pointer bytes could be 72 /Users/shaowenchen/Code/app/config/config.go:209:12: struct with 56 pointer bytes could be 40 /Users/shaowenchen/Code/app/dao/gormx/gorm.go:12:13: struct with 16 pointer bytes could be 8 /Users/shaowenchen/Code/app/dao/gormx/entity/cluster.go:5:14: struct with 128 pointer bytes could be 104 查看 fieldalignment 进行

使用 Alpine 镜像常见问题
· ☕ 1 分钟
1. DNS 请求超时 原因: alpine 使用的是 musl 库,在 DNS 解析上会有一些限制[1] 解决方式: 不使用 apline 镜像,并在容器 resolv.conf 文件中增加 options single-request-reopen 配置。因为 single-request-reopen 配置项只对 glibc 库生效,但是 apline 镜像使用的是 musl 库 2. Docker 下无法解析 hosts 原因: alpine 没有 /etc/nsswitch.conf,导致依赖 hosts

流水线构建时,凭证作用域问题
· ☕ 2 分钟
在 client 中已经看到 Docker CLI 在给 Docker Daemon 发生构建上下文时,通过设置 X-Registry-Config 传递凭证,但在最近的构建反馈中,还是会出现一些无法解释的现象,本篇主要是进行一些基础的测试,以便于更好排查问题。 1. 宿主机 Docker 下构建 Docker Daemon 以 root 用户权限启动。 未登录任何账户 1 2 3 4 su ansible echo "FROM harbor.chenshaowen.com/private/test:v1" | sudo

排查构建镜像时 IO 慢问题
· ☕ 6 分钟
1. 遇到的问题 项目介绍: 文件大小 5.6 GB 文件数量 529352 Dockerfile 1 2 3 FROM golang:1.13 COPY ./ /go/src/code 构建命令及输入如下: 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 time DOCKER_BUILDKIT=1 docker build --no-cache -t test:v3 -f Dockerfile . --progress=plain #1 [internal] load build definition from Dockerfile #1 sha256:2a154d4ad813d1ef3355d055345ad0e7c5e14923755cea703d980ecc1c576ce7 #1 transferring dockerfile: 37B done #1 DONE 0.1s #2 [internal] load .dockerignore #2 sha256:9598c0ddacf682f2cac2be6caedf6786888ec68f009c197523f8b1c2b5257b34 #2 transferring context: 2B

Dockerfile 中 Run mv 比 cp 慢
· ☕ 4 分钟
不同于 CentOS、Ubuntu,我们感受到 mv 比 cp 快;在使用 Dockerfile 构建镜像时,使用 Run cp 会比 Run mv 更快。本篇将给出相关的一些测试、验证的数据结果。 1. 测试准备 机器环境 Ubuntu 20.04.1 LTS 32C 125Gi 由于是生产机器,上面会有些负载,因此测试会有偏差。我会多次测试,等结果稳定