2

I have created a container from httpd docker image via Dockerfile:

FROM httpd:2.4

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

The public-html file contains just a simple html file:

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

Then I created the container:

# docker build -t apachehttpd .

And started:

docker run -dit -p 8080:80 apachehttpd

The container is up and running:

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 says that it's really listening:

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

However the website is not reachable via browser nor cURL. But with telnet I am able to connect to the socket, but with GET it returns "Bad Request":

# 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

And I can see my requests in logs:

# 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

Could you please support me, why the page is not accessible via browser?

SidiousD
  • 21
  • 1
  • 3
  • does http://172.17.0.2:8080 work? That seems to be the address the server is binding to. – avigil Mar 17 '18 at 20:22
  • I followed your steps and it worked for me with no issue. Try to repull `httpd:2.4` – er-han Mar 17 '18 at 20:44
  • I did a repull, but still the same behavior. the 172.17.0.2:8080 doesn't work # curl -v telnet://172.17.0.2:8080 * About to connect() to 172.17.0.2 port 8080 (#0) * Trying 172.17.0.2... * Connection refused * Failed connect to 172.17.0.2:8080; Connection refused * Closing connection 0 curl: (7) Failed connect to 172.17.0.2:8080; Connection refused – SidiousD Mar 17 '18 at 21:47
  • this is my network interface: 3: docker0: mtu 1500 qdisc noqueue state UP link/ether 02:42:1d:ca:4c:97 brd ff:ff:ff:ff:ff:ff inet 172.17.0.1/16 brd 172.17.255.255 scope global docker0 valid_lft forever preferred_lft forever inet6 fe80::42:1dff:feca:4c97/64 scope link valid_lft forever preferred_lft forever – SidiousD Mar 17 '18 at 21:49

3 Answers3

1

The only thing you missing is to create the user and set permissions. due to not any permission cause to kill container and through error.

Here is my docker file with little modification.

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

my index.html

    <html>
    <h1>

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

And here wo go :)

enter image description here

Adiii
  • 54,482
  • 7
  • 145
  • 148
  • 1
    Still not working. It seems the issue is somewhere else. The curl -v telnet://10.233.174.147:80 gives 400 Bad Request The browser Mozilla returns: internal error - server connection terminated But a telnet from Windows' cmd is working, also the connection from Chrome is working. – SidiousD Mar 17 '18 at 22:45
  • did u build your docker again ? – Adiii Mar 17 '18 at 22:47
  • you doing on wrong port curl -v telnet://10.233.174.147:80 you expose port 8080 instead of 80 – Adiii Mar 17 '18 at 22:51
  • and try to open in private window – Adiii Mar 17 '18 at 22:52
  • Yes, I did. It seems some issues with Firefox, since on Chrome it's running well – SidiousD Mar 17 '18 at 22:57
  • Thanks God :D may be issue with firfrox – Adiii Mar 17 '18 at 22:58
1

I tried everything of this answer Permission issues with Apache inside Docker unlucky

Just this worked for me:

RUN chown www-data:www-data /usr/local/apache2/htdocs/ -R

Here my complete Dockerfile

FROM httpd:2.4
WORKDIR /usr/local/apache2/htdocs/
RUN chmod -R 755 /usr/local/apache2/htdocs/
COPY ./index.html /usr/local/apache2/htdocs/
RUN chown www-data:www-data /usr/local/apache2/htdocs/ -R

If don't work, put the chmod sentence inside of container using the ENTRYPOINT ["entrypoint.sh"]

JRichardsz
  • 14,356
  • 6
  • 59
  • 94
0

1) Open Kinematic and go check whether container is ruining or not .

2) Click on highlighted arrow it will open link in new browser .

enter image description here

enter image description here

enter image description here

vaquar khan
  • 10,864
  • 5
  • 72
  • 96