Docker HTTPD正在运行,但网站无法访问

时间:2018-03-17 20:15:51

标签: apache docker

我已经通过Dockerfile从httpd docker image创建了一个容器:

FROM httpd:2.4

COPY ./public-html/ /usr/local/apache2/htdocs/

public-html文件只包含一个简单的html文件:

# cat public-html/index.html
<html>
<body>
Simple Page
</body>
</html>

然后我创建了容器:

# docker build -t apachehttpd .

开始了:

docker run -dit -p 8080:80 apachehttpd

容器已启动并正在运行:

CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
0912f4f7d1a8        apachehttpd         "httpd-foreground"   19 hours ago        Up 19 hours         0.0.0.0:8080->80/tcp   keen_almeida

Netstat说它真的在听:

tcp6       0      0 :::8080                 :::*                    LISTEN

但是,无法通过浏览器或cURL访问该网站。但是使用telnet我可以连接到套接字,但是使用GET它会返回&#34; Bad Request&#34;:

# curl -v telnet://localhost:8080
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
GET /
HTTP/1.1 400 Bad Request
Date: Sat, 17 Mar 2018 19:28:45 GMT
Server: Apache/2.4.29 (Unix)
Content-Length: 226
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
</body></html>

* Closing connection 0

我可以在日志中看到我的请求:

# docker logs 0912f4f7d1a8
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Sat Mar 17 00:32:09.681368 2018] [mpm_event:notice] [pid 1:tid 139650427893632] AH00489: Apache/2.4.29 (Unix) configured -- resuming normal operations
[Sat Mar 17 00:32:09.681422 2018] [core:notice] [pid 1:tid 139650427893632] AH00094: Command line: 'httpd -D FOREGROUND'
172.17.0.1 - - [17/Mar/2018:18:52:41 +0000] "GET /" 400 226
172.17.0.1 - - [17/Mar/2018:19:21:56 +0000] "GET /index.html" 400 226
172.17.0.1 - - [17/Mar/2018:19:28:45 +0000] "GET /" 400 226

您能否支持我,为什么无法通过浏览器访问该页面?

2 个答案:

答案 0 :(得分:1)

您唯一缺少的是创建用户并设置权限。由于没有任何许可导致杀死容器和错误。

这是我的docker文件,几乎没有修改。

FROM httpd:2.4
COPY index.html /usr/local/apache2/htdocs/index.html
RUN  mkdir -p /run/apache2/ && \
     chown www-data:www-data /run/apache2/ && \
     chmod 777 /run/apache2/

EXPOSE 80 443

我的index.html

    <html>
    <h1>

        Welcome to docker :)
    </h1>
</html>

这就是去吧:)。

enter image description here

答案 1 :(得分:0)

1)打开Kinematic,然后检查容器是否在损毁。

2)单击突出显示的箭头,它将在新的浏览器中打开链接。

enter image description here

enter image description here

enter image description here