一、Caddy介绍
Caddy是一个Go语言编写的开源web服务器,同时也是具有自动HTTPS的快速且可扩展的多平台 HTTP/1-2-3 Web 服务器。
二、检查本地环境
1.检查系统版本
[root@jeven ~]# cat /etc/os-release
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"
CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"
2.检查docker状态
[root@jeven ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2022-12-02 04:34:05 CST; 2 days ago
Docs: https://docs.docker.com
Main PID: 10004 (dockerd)
Tasks: 114
Memory: 2.2G
CGroup: /system.slice/docker.service
├─10004 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
三、下载caddy镜像
[root@jeven ~]# docker pull caddy
Using default tag: latest
latest: Pulling from library/caddy
97518928ae5f: Already exists
23ccae726125: Pull complete
3de6a61c89ac: Pull complete
39ed957bdc00: Pull complete
0ae44c2d42dd: Pull complete
Digest: sha256:9e28571098b64a89019e3698b332f44955202fd53df5227f58a68fb395e80880
Status: Downloaded newer image for caddy:latest
docker.io/library/caddy:latest
四、部署caddy应用
1.创建数据目录
[root@jeven ~]# mkdir /data/caddy
[root@jeven ~]# cd /data/
2.新建测试网页文件
[root@jeven caddy]# echo " caddy website --- myweb" >> index.html
[root@jeven caddy]#
3.创建caddy容器
docker run -d -p 8266:80 \
-v $PWD/index.html:/usr/share/caddy/index.html \
-v /data/caddy/data:/data \
caddy
4.查看caddy容器状态
[root@jeven caddy]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b12f803a11a5 caddy "caddy run --config …" 25 seconds ago Up 23 seconds 443/tcp, 2019/tcp, 0.0.0.0:8266->80/tcp, :::8266->80/tcp ecstatic_wilbur
5.查看caddy容器运行日志
[root@jeven caddy]# docker logs ecstatic_wilbur
{"level":"info","ts":1670167084.1306765,"msg":"using provided configuration","config_file":"/etc/caddy/Caddyfile","config_adapter":"caddyfile"}
{"level":"info","ts":1670167084.132184,"logger":"admin","msg":"admin endpoint started","address":"tcp/localhost:2019","enforce_origin":false,"origins":["localhost:2019","[::1]:2019","127.0.0.1:2019"]}
{"level":"info","ts":1670167084.1322808,"logger":"http","msg":"server is listening only on the HTTP port, so no automatic HTTPS will be applied to this server","server_name":"srv0","http_port":80}
{"level":"info","ts":1670167084.1325452,"msg":"autosaved config (load with --resume flag)","file":"/config/caddy/autosave.json"}
{"level":"info","ts":1670167084.1325657,"msg":"serving initial configuration"}
{"level":"info","ts":1670167084.1327555,"logger":"tls","msg":"cleaning storage unit","description":"FileStorage:/data/caddy"}
{"level":"info","ts":1670167084.1327794,"logger":"tls","msg":"finished cleaning storage units"}
{"level":"info","ts":1670167084.1328008,"logger":"tls.cache.maintenance","msg":"started background certificate maintenance","cache":"0xc0001cb1f0"}
五、访问caddy应用