云原生之使用Docker部署caddy网站服务器

举报
江湖有缘 发表于 2022/12/04 23:20:41 2022/12/04
【摘要】 云原生之使用Docker部署caddy网站服务器

一、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应用

image.png

【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。