云原生之使用docker部署httpd服务

2023-01-27 21:28:12 浏览数 (1)

一、检查系统版本

代码语言:shell复制
[root@node ~]# 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"

二、检查docker状态

1.检查docker版本

代码语言:shell复制
[root@node ~]# docker -v
Docker version 20.10.17, build 100c701

2.检查docker状态

代码语言:shell复制
[root@node ~]# 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 Mon 2022-10-31 03:28:51 CST; 3 days ago
     Docs: https://docs.docker.com
 Main PID: 11884 (dockerd)
    Tasks: 45
   Memory: 3.4G
   CGroup: /system.slice/docker.service
           ├─11884 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
           ├─89868 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8100 -container-ip 172.17.0.2 -container-port 8100
           ├─89875 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8100 -container-ip 172.17.0.2 -container-port 8100
           ├─95298 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 3541 -container-ip 172.17.0.3 -container-port 3306
           └─95304 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 3541 -container-ip 172.17.0.3 -container-port 3306

Nov 03 11:28:02 node dockerd[11884]: time="2022-11-03T11:28:02.013519308 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:02 node dockerd[11884]: time="2022-11-03T11:28:02.762364306 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:03 node dockerd[11884]: time="2022-11-03T11:28:03.262033832 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:03 node dockerd[11884]: time="2022-11-03T11:28:03.961466550 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:05 node dockerd[11884]: time="2022-11-03T11:28:05.051145634 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:06 node dockerd[11884]: time="2022-11-03T11:28:06.966059311 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:10 node dockerd[11884]: time="2022-11-03T11:28:10.473723379 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:17 node dockerd[11884]: time="2022-11-03T11:28:17.261643944 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:30 node dockerd[11884]: time="2022-11-03T11:28:30.396312249 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Nov 03 11:28:56 node dockerd[11884]: time="2022-11-03T11:28:56.355217126 08:00" level=info msg="ignoring event" container=48b7ba756f8ee7...kDelete"
Hint: Some lines were ellipsized, use -l to show in full.

三、搜索httpd镜像

代码语言:shell复制
[root@node ~]# docker search httpd
NAME                                 DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
httpd                                The Apache HTTP Server Project                  4228      [OK]       
centos/httpd-24-centos7              Platform for running Apache httpd 2.4 or bui…   44                   
centos/httpd                                                                         35                   [OK]
arm32v7/httpd                        The Apache HTTP Server Project                  11                   
solsson/httpd-openidc                mod_auth_openidc on official httpd image, ve…   2                    [OK]
clearlinux/httpd                     httpd HyperText Transfer Protocol (HTTP) ser…   2                    
hypoport/httpd-cgi                   httpd-cgi                                       2                    [OK]
dockerpinata/httpd                                                                   1                    
manageiq/httpd                       Container with httpd, built on CentOS for Ma…   1                    [OK]
publici/httpd                        httpd:latest                                    1                    [OK]
inanimate/httpd-ssl                  A play container with httpd, ssl enabled, an…   1                    [OK]
dariko/httpd-rproxy-ldap             Apache httpd reverse proxy with LDAP authent…   1                    [OK]
nnasaki/httpd-ssi                    SSI enabled Apache 2.4 on Alpine Linux          1                    
lead4good/httpd-fpm                  httpd server which connects via fcgi proxy h…   1                    [OK]
centos/httpd-24-centos8                                                              1                    
patrickha/httpd-err                                                                  0                    
httpdss/archerysec                   ArcherySec repository                           0                    [OK]
e2eteam/httpd                                                                        0                    
amd64/httpd                          The Apache HTTP Server Project                  0                    
manageiq/httpd_configmap_generator   Httpd Configmap Generator                       0                    [OK]
httpdocker/kubia                                                                     0                    
paketobuildpacks/httpd                                                               0                    
ppc64le/httpd                        The Apache HTTP Server Project                  0                    
19022021/httpd-connection_test       This httpd image will test the connectivity …   0                    
manasip/httpd                                                                        0  

四、下载httpd镜像

代码语言:shell复制
[root@node ~]# docker pull httpd:2.4
2.4: Pulling from library/httpd
a2abf6c4d29d: Already exists 
dcc4698797c8: Pull complete 
41c22baa66ec: Pull complete 
67283bbdd4a0: Pull complete 
d982c879c57e: Pull complete 
Digest: sha256:0954cc1af252d824860b2c5dc0a10720af2b7a3d3435581ca788dff8480c7b32
Status: Downloaded newer image for httpd:2.4
docker.io/library/httpd:2.4

五、创建httpd容器

1.创建数据目录

代码语言:shell复制
[root@node ~]# mkdir -p /data/httpd
[root@node ~]# cd /data/httpd/

2.运行httpd容器

代码语言:shell复制
[root@node httpd]# docker run -dit --name my-apache -p 8680:80 -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4
6490b46fe58d5f9837e9fcbef8b1e7767048fffe6ce7480c3764ba43ae91f313

3.查看httpd容器状态

代码语言:shell复制
[root@node httpd]# docker ps
CONTAINER ID   IMAGE               COMMAND                  CREATED          STATUS          PORTS                                                  NAMES
6490b46fe58d   httpd:2.4           "httpd-foreground"       27 seconds ago   Up 26 seconds   0.0.0.0:8680->80/tcp, :::8680->80/tcp                  my-apache

六、访问httpd服务

在这里插入图片描述在这里插入图片描述

七、编辑index.html文件

1.编辑index.html文件

代码语言:shell复制
[root@node httpd]# echo "aa-my-web-linux   ---"  > index.html
[root@node httpd]# ls
index.html

2.访问网站内容

代码语言:shell复制
[root@node httpd]# curl 192.168.3.166:8680
aa-my-web-linux   ---

3.浏览器访问httpd服务

在这里插入图片描述在这里插入图片描述

0 人点赞