Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message

容器2022-08-11
Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

故障描述:宿主机Centos7下安装docker服务,有一个提供web服务的容器,已经设置容器跟随docker服务器自启动,但是每当重启Centos7后,其他容器正常,唯有这一个容器的web服务不正常,无法访问。

解决办法:在apache的默认配置文件内增加 ServerName IP

Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

故障处理:重启CentOS后查看不正常的容器日志:

$ docker logs --since 30m CONTAINER_ID //查看30分钟内的日志
Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

1.如上图可见容器内apache有报错:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message

查看出问题的容器的IP,确定容器IP为172.17.0.5

$ docker inspect CONTAINER_ID | grep IPAddress
Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

2.此报错可能是因为apache的配置文件没有定义 ServerName 这一项,需要添加:

ServerName 172.17.0.5

$ odcker exec -it CONTAINER_ID bash  //进入容器
$ cat /etc/apache2/sites-enable/000-defalut.conf //查看配置文件
Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

3.如上图 #ServerName 是被注释的,问题处理就很简单了,直接取消注释,新增一条:

ServerName 172.17.0.5

4.但是容器里边没有vim编辑器,怎么办?

Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

直接从容器中拷贝文件到宿主机,然后在宿主机修改完成后拷贝进容器

$docker cp host_path containerID:container_path  //从主机复制到容器
$docker cp containerID:container_path host_path  //从容器复制到主机

复制完成后,注意在容器中检查文件权限配置是否和之前一致

Docker容器报错处理:AH00558: apache2: Could not reliably determine the server’s fully qualified domain name, using 172.17.0.5. Set the ‘ServerName’ directive globally to suppress this message-下一朵云

检查一致,Ctrl+d退出容器,重启容器

$ docker restart CONTAINER_ID

5.容器web服务正常访问!重启宿主机,之前的故障消失。

附:docker查看日志记录

 命令格式:
 $ docker logs [OPTIONS] CONTAINER
   Options:
         --details        显示更多的信息
     -f, --follow         跟踪实时日志
         --since string   显示自某个timestamp之后的日志,或相对时间,如42m(即42分钟)
         --tail string    从日志末尾显示多少行日志, 默认是all
     -t, --timestamps     显示时间戳
         --until string   显示自某个timestamp之前的日志,或相对时间,如42m(即42分钟)
 例子:
 查看指定时间后的日志,只显示最后100行:
 $ docker logs -f -t --since="2018-02-08" --tail=100 CONTAINER_ID
 查看最近30分钟的日志:
 $ docker logs --since 30m CONTAINER_ID
 查看某时间之后的日志:
 $ docker logs -t --since="2018-02-08T13:23:37" CONTAINER_ID
 查看某时间段日志:
 $ docker logs -t --since="2018-02-08T13:23:37" --until "2018-02-09T12:23:37" CONTAINER_ID