SidiousD
SidiousD

Reputation: 21

Docker HTTPD running, but the website is not accessible

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?

Upvotes: 2

Views: 7379

Answers (3)

JRichardsz
JRichardsz

Reputation: 16524

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"]

Upvotes: 1

vaquar khan
vaquar khan

Reputation: 11449

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

Upvotes: 0

Adiii
Adiii

Reputation: 59966

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

Upvotes: 1

Related Questions