Write the Code. Change the World.

11月 12

好几年前,ssl 免费证书有效期为 3 个月。搞一个能生成证书的环境就比较方便。

构建带 certbot 的 nginx 镜像

  1. 准备 Dockerfile 文件。
FROM nginx:1.29.3

# 安装 certbot https://certbot.eff.org/instructions?ws=nginx&os=snap
# 也可以在 nginx 之外使用 certbot 镜像 https://hub.docker.com/r/certbot/certbot
RUN apt-get update && \
    apt-get install -y python3-venv && \
    python3 -m venv /opt/certbot && \
    /opt/certbot/bin/pip install certbot certbot-nginx && \
    ln -s /opt/certbot/bin/certbot /usr/local/bin/certbot && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*
  1. 打包镜像

    docker build -t xr-nginx:1.29.3 .
  2. 运行镜像,生成容器服务。然后打开浏览器,输入 http://localhost 查看情况。

docker run --rm -it -p 80:80 --name xr-nginx xr-nginx:1.29.3

# 查看日志
docker run --rm -it -p 80:80 xr-nginx:1.29.3

# 进入容器
received

然后镜既有 nginx 的功能,还能生成证书。

生成证书

  1. 生成证书需要域名解析指向服务器。
  2. 需要挂载好证书存储位置,防止 docker 关闭启动后 丢失证书。( ./conf/nginx/letsencrypt:/etc/letsencrypt)
# 容器外运行
docker exec -i xr-nginx sh -c "certbot -d xxx.com"

# 进入容器运行
docker exec -it xr-nginx bash
certbot -d xxx.com

其他

https://blog.vini123.com/1299

https://blog.vini123.com/1293

11月 12

https://blog.csdn.net/weixin_39938069/article/details/144372076

构建国产东方通

  1. 准备好安装包和 license。
  2. 准备 Dockerfile 文件。
FROM alpine:3.18

# 1. 安装编译依赖
RUN apk add --no-cache \
        gcc g++ make autoconf automake libtool bison flex \
        openssl-dev zlib-dev pcre-dev tar

# 2. 复制源码和 license
COPY TongHttpServer_6.0.1.5_alpine_x86_64.tar.gz /tmp/
COPY license.dat /tmp/

# 3. 解压
RUN tar -zxf /tmp/TongHttpServer_6.0.1.5_alpine_x86_64.tar.gz -C /usr/local/ && \
    cp /tmp/license.dat /usr/local/THS/ && \
    rm -f /tmp/TongHttpServer_6.0.1.5_alpine_x86_64.tar.gz && \
    rm -f /tmp/license.dat

# 4. 设置工作目录
WORKDIR /usr/local/THS

# 暴露端口,根据需要修改
EXPOSE 80 443 8011 8000

# 启动 TongHttpServer
CMD ["./bin/start.sh"]

安装包有 x86 和 arm64,请和服务器对应上。

  1. 打包镜像。Dockerfile 文件、安装包、license 文件放一起。

    docker build -t tong-http-server:6.0.1 .
  2. 运行镜像,看看效果

docker run -d --rm -p 8000:8000 -p 80:80 --name t1 \
  tong-http-server:6.0.1 \
  /bin/sh -c "./bin/start.sh && ./bin/startConsole.sh && tail -f /dev/null"

# 进入容器查看
docker exec -it t1 bash

浏览器访问 http://localhost:8000 进入控制台。

11月 12

默认情况下,win10 打包的 docker 镜像是 x86 架构平台的。有的服务器 cpu 是 arm 架构的,这个时候打包成 arm 架构的镜像就很有必要。或者是在服务器上去构建镜像。

win10 打包 arm 平台 docker 镜像

  1. 创建并启用 arm64 构建器. arm-builder 是构建器名称。

    docker buildx create --name arm-builder --use --platform linux/amd64,linux/arm64
  2. 准备好 Dockerfile 文件。 进行构建。 my-app-arm64 是镜像名字,1.0 是镜像版本。

    docker buildx build --platform linux/arm64 -t my-app-arm64:1.0 --load .
  3. 构建成功后,验证一下。

    docker run --rm -it --platform linux/arm64 my-app-arm64:1.0 uname -m
  4. 推送到远程仓库

    docker tag my-app-arm64:1.0 xxxx仓库地址/my-app-arm64:1.0
    docker push xxxx仓库地址/my-app-arm64:1.0

后续

# 查看构建器列表
docker buildx ls

# 切换构建器 
docker buildx use default (默认构建器)
docker buildx use desktop-linux (desktop-linux 构建器)
# 删除镜像构建器
docker buildx rm arm-buildx