<!-- review: finished -->

<a id="docker-images"></a>

# Angie Docker 镜像

要在 [Docker](https://docs.docker.com/engine/reference/commandline/cli/) 容器中运行 Angie,
请使用我们注册表中的镜像:`docker.angie.software`。
这些镜像基于我们的 [二进制软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
和几个操作系统的官方基础镜像构建。

#### NOTE
另请注意 [Docker](https://cn.angie.software//angie/docs/configuration/modules/http/http_docker.md#http-docker) 模块,
该模块基于 Docker 容器标签实现上游服务器组的动态更新。

<a id="minimal-images"></a>

## 最小化镜像

- `angie:minimal`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>-minimal`:
  基于 Alpine 3.22 的指定版本。

这些镜像仅包含 `angie` 软件包。

<a id="docker-templated"></a>

## 模板化镜像

- `angie:templated`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>-templated`:
  基于 Alpine 3.22 的指定版本。

这些镜像设置了以下环境变量:

```docker
ENV ANGIE_BINARY="angie"
ENV ANGIE_CONFIG_TEMPLATE="/etc/angie/angie.conf.t"
ENV ANGIE_ERROR_LOG_SEVERITY="notice"
ENV ANGIE_FEATURE_RELOAD="on"
ENV ANGIE_FEATURE_TEMPLATE="on"
ENV ANGIE_LOAD_MODULES=""
ENV ANGIE_PID_FILE="/run/angie/angie.pid"
ENV ANGIE_WORKER_CONNECTIONS="65536"
ENV ANGIE_WORKER_RLIMIT_NOFILE="65536"
```

这些变量可用于自定义容器行为:

- `ANGIE_BINARY`:
  允许运行 [调试版本](https://cn.angie.software//angie/docs/troubleshooting.md#debug-logging)。
- `ANGIE_ERROR_LOG_SEVERITY`:
  设置主 [错误日志](https://cn.angie.software//angie/docs/configuration/processing.md#logging) 文件中条目的严重级别。
- `ANGIE_LOAD_MODULES`:
  加载一个或多个可用模块(镜像中包含所有模块)。
  指定以逗号分隔的模块列表,不含空格。
- `ANGIE_PID_FILE`:
  设置进程标识符 (PID) 文件的替代位置。
- `ANGIE_FEATURE_TEMPLATE`:
  在容器启动时使用 [gomplate](https://docs.gomplate.ca/) 工具生成
  [Angie 配置](https://cn.angie.software//angie/docs/configuration/configfile.md#configfile)。使用的参数:
  `--input-dir /etc/angie/templates` 和
  `--output-dir /etc/angie`。
- `ANGIE_FEATURE_RELOAD`:
  启用对 `SIGHUP`、`SIGQUIT` 和 `SIGTERM`
  信号的处理。

这些镜像包含以下
[软件包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)
(如果它们已针对构建镜像所用的 [Angie 版本](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes) 发布):

### 软件包列表

- `angie-console-light`
- `angie-module-auth-jwt`
- `angie-module-auth-ldap`
- `angie-module-auth-pam`
- `angie-module-auth-spnego`
- `angie-module-auth-totp`
- `angie-module-brotli`
- `angie-module-cache-purge`
- `angie-module-cgi`
- `angie-module-combined-upstreams`
- `angie-module-dav-ext`
- `angie-module-dynamic-limit-req`
- `angie-module-echo`
- `angie-module-enhanced-memcached`
- `angie-module-eval`
- `angie-module-geoip2`
- `angie-module-headers-more`
- `angie-module-http-auth-radius`
- `angie-module-image-filter`
- `angie-module-keyval`
- `angie-module-lua`
- `angie-module-modsecurity`
- `angie-module-ndk`
- `angie-module-njs`
- `angie-module-opentracing`
- `angie-module-otel`
- `angie-module-perl`
- `angie-module-postgres`
- `angie-module-redis2`
- `angie-module-rtmp`
- `angie-module-set-misc`
- `angie-module-subs`
- `angie-module-testcookie`
- `angie-module-unbrotli`
- `angie-module-upload`
- `angie-module-vod`
- `angie-module-vts`
- `angie-module-wasm`
- `angie-module-wasmtime`
- `angie-module-xslt`
- `angie-module-zip`
- `angie-module-zstd`

<a id="examples-1"></a>

### 示例

模板化镜像中使用的配置大致按以下方式应用变量:

```none
...
{{- if has $modules "zstd"}}
# package: angie-module-zstd
load_module modules/ngx_http_zstd_filter_module.so;
load_module modules/ngx_http_zstd_static_module.so;
{{end}}

user  angie;
worker_processes  auto;
worker_rlimit_nofile {{.Env.ANGIE_WORKER_RLIMIT_NOFILE}};

error_log  /var/log/angie/error.log {{.Env.ANGIE_ERROR_LOG_SEVERITY}};
pid        {{.Env.ANGIE_PID_FILE}};

events {
    worker_connections  {{.Env.ANGIE_WORKER_CONNECTIONS}};
}

http {
    include       /etc/angie/mime.types;
    default_type  application/octet-stream;

    log_format  main  ...
```

运行具有 shell 访问权限的容器:

```console
$ docker run -it --pull always --rm --entrypoint=sh \
  docker.angie.software/angie:templated
```

使用自定义连接参数和模块运行 Angie
(命令 **angie -T** 将输出完整配置):

```console
$ docker run -it --rm -e ANGIE_WORKER_CONNECTIONS=4 \
  -e ANGIE_LOAD_MODULES="auth-jwt,vod" \
  docker.angie.software/angie:templated angie -T
```

启动具有指定名称和附加模块的容器:

```console
$ docker run -it --rm --name angie-test \
  -e ANGIE_WORKER_CONNECTIONS=4 \
  -e ANGIE_LOAD_MODULES="auth-jwt,vod" \
  docker.angie.software/angie:templated
```

重新加载正在运行的容器的配置:

```console
$ docker kill -s HUP angie-test
```

<a id="images-with-extra-modules"></a>

## 包含额外模块的镜像

- `angie:latest`:
  基于 Alpine 3.22 的  版本。
- `angie:<VERSION>`,
  `angie:<VERSION>-alpine`:
  基于 Alpine 3.22 的指定版本。
- `angie:<VERSION>-debian`:
  基于 Debian 13 的指定版本。
- `angie:<VERSION>-rocky`:
  基于 Rocky Linux 9 的指定版本。
- `angie:<VERSION>-ubuntu`:
  基于 Ubuntu 24.04 LTS 的指定版本。

这些镜像包含以下
[软件包](https://cn.angie.software//angie/docs/installation/external-modules/index.md#install-thirdpartymodules)
(如果它们已针对构建镜像所用的 [Angie 版本](https://cn.angie.software//angie/docs/oss_changes.md#oss-changes) 发布):

### 软件包列表

- `angie-console-light`
- `angie-module-auth-jwt`
- `angie-module-auth-ldap`
- `angie-module-auth-pam`
- `angie-module-auth-spnego`
- `angie-module-auth-totp`
- `angie-module-brotli`
- `angie-module-cache-purge`
- `angie-module-cgi`
- `angie-module-combined-upstreams`
- `angie-module-dav-ext`
- `angie-module-dynamic-limit-req`
- `angie-module-echo`
- `angie-module-enhanced-memcached`
- `angie-module-eval`
- `angie-module-geoip2`
- `angie-module-headers-more`
- `angie-module-http-auth-radius`
- `angie-module-image-filter`
- `angie-module-keyval`
- `angie-module-lua`
- `angie-module-modsecurity`
- `angie-module-ndk`
- `angie-module-njs`
- `angie-module-opentracing`
- `angie-module-otel`
- `angie-module-perl`
- `angie-module-postgres`
- `angie-module-redis2`
- `angie-module-rtmp`
- `angie-module-set-misc`
- `angie-module-subs`
- `angie-module-testcookie`
- `angie-module-unbrotli`
- `angie-module-upload`
- `angie-module-vod`
- `angie-module-vts`
- `angie-module-wasm`
- `angie-module-wasmtime`
- `angie-module-xslt`
- `angie-module-zip`
- `angie-module-zstd`

<a id="running"></a>

## 运行

要在端口 8080 上启动带有 Angie 的容器,
提供对静态文件目录 `/var/www/` 的只读访问
以及位于当前工作目录中的配置文件 `angie.conf`:

```console
$ docker run --rm --name angie -v /var/www:/usr/share/angie/html:ro \
    -v $(pwd)/angie.conf:/etc/angie/angie.conf:ro -p 8080:80 -d docker.angie.software/angie:latest

$ curl -I localhost:8080

    HTTP/1.1 200 OK
    Server: Angie/|version|
    Date: |sampledatelong| 10:42:54 GMT
    Content-Type: text/html
    Content-Length: 543
    Last-Modified: |sampledatelong| 09:12:23 GMT
    Connection: keep-alive
    ETag: "64c3ccc7-21f"
    Accept-Ranges: bytes
```

此类配置适用于本地开发和配置。

<a id="building-custom-images"></a>

## 构建自定义镜像

您也可以基于支持的发行版构建自己的镜像,
从 [软件包](https://cn.angie.software//angie/docs/installation/oss_packages.md#oss-packages)
或 [源代码](https://cn.angie.software//angie/docs/installation/sourcebuild.md#sourcebuild) 添加 Angie 层。
相应的 `Dockerfile` 文件示例:

```dockerfile
FROM debian:13

LABEL org.opencontainers.image.authors="Release Engineering Team <devops@tech.wbsrv.ru>"

ARG DEBIAN_FRONTEND=noninteractive

RUN set -x \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y \
          ca-certificates curl \
     && curl -o /etc/apt/trusted.gpg.d/angie-signing.gpg \
          https://angie.software/keys/angie-signing.gpg \
     && echo "deb https://download.angie.software/angie/$(. /etc/os-release && echo "$ID/$VERSION_ID $VERSION_CODENAME") main" \
          > /etc/apt/sources.list.d/angie.list \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y \
          angie angie-module-geoip2 angie-module-njs \
     && rm -Rf /var/lib/apt/lists \
          /etc/apt/sources.list.d/angie.list \
          /etc/apt/trusted.gpg.d/angie-signing.gpg \
     && ln -sf /dev/stdout /var/log/angie/access.log \
     && ln -sf /dev/stderr /var/log/angie/error.log

EXPOSE 80

CMD ["angie", "-g", "daemon off;"]
```

```dockerfile
FROM alpine:3.22

LABEL org.opencontainers.image.authors="Release Engineering Team <devops@tech.wbsrv.ru>"

RUN set -x \
     && apk add --no-cache ca-certificates curl \
     && curl -o /etc/apk/keys/angie-signing.rsa https://angie.software/keys/angie-signing.rsa \
     && echo "https://download.angie.software/angie/alpine/v$(egrep -o \
          '[0-9]+\.[0-9]+' /etc/alpine-release)/main" >> /etc/apk/repositories \
     && apk add --no-cache angie angie-module-geoip2 angie-module-njs \
     && rm /etc/apk/keys/angie-signing.rsa \
     && ln -sf /dev/stdout /var/log/angie/access.log \
     && ln -sf /dev/stderr /var/log/angie/error.log

EXPOSE 80

CMD ["angie", "-g", "daemon off;"]
```

要在包含此类 `Dockerfile` 的目录中构建 `myangie` 镜像
并按上述方式启动容器:

```console
$ docker build -t myangie .
$ docker run --rm --name myangie -v /var/www:/usr/share/angie/html:ro \
    -v $(pwd)/angie.conf:/etc/angie/angie.conf:ro -p 8080:80 -d myangie
```
