Jump to content

Docker: site fails to load


Recommended Posts

Hi,

I am just trying out the docker example here

It works with some minor changes to the dockerfile.

Working dockerfile :

FROM ubuntu:18.04
MAINTAINER Dan Pupius <dan@pupi.us>

# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
    apache2 php7.2 php7.2-mysql libapache2-mod-php7.2 curl lynx-common lynx	

# Enable apache mods.
RUN a2enmod php7.2
RUN a2enmod rewrite

# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.2/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.2/apache2/php.ini

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

# Expose apache.
EXPOSE 80

# Copy this repo into place.
ADD www /var/www/site

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUNDs

 

However I am unable to access the site on the browser on localhost.

Bashing into the server shows no errors. Everything seems to be in place, the vhost files are there. It is enabled. I even tried with the IP address in hosts file. But no luck. 

Anything else I should check ? What could I be missing here. I am spinning the container off centos7 and not using windows.

Thanks.

 

Link to post
Share on other sites

Hi all,

Apologies for REPOSTING as a part of the message had a wrong font color and was invisible.

I am just trying out the docker example here

It works with some minor changes to the dockerfile.

Working dockerfile :

FROM ubuntu:

FROM ubuntu:18.04
MAINTAINER Dan Pupius <dan@pupi.us>

# Install apache, PHP, and supplimentary programs. openssh-server, curl, and lynx-cur are for debugging the container.
RUN apt-get update && apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
    apache2 php7.2 php7.2-mysql libapache2-mod-php7.2 curl lynx-common lynx	

# Enable apache mods.
RUN a2enmod php7.2
RUN a2enmod rewrite

# Update the PHP.ini file, enable <? ?> tags and quieten logging.
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.2/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.2/apache2/php.ini

# Manually set up the apache environment variables
ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

# Expose apache.
EXPOSE 80

# Copy this repo into place.
ADD www /var/www/site

# Update the default apache site with the config we created.
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf

# By default start up apache in the foreground, override with /bin/bash for interative.
CMD /usr/sbin/apache2ctl -D FOREGROUNDs

However I am unable to access the site on the browser on localhost. I get a page which says

Hmm. We’re having trouble finding that site.

We can’t connect to the server at www.test.local.

If that address is correct, here are three other things you can try:

    Try again later.
    Check your network connection.
    If you are connected but behind a firewall, check that Firefox has permission to access the Web.

Bashing into the server shows no errors. Everything seems to be in place, the vhost files are there. It is enabled. I even tried with the IP address in hosts file. But no luck. 

Anything else I should check ? What could I be missing here. I am spinning the container off centos7 and not using windows.

Thanks !

Link to post
Share on other sites

Hi requinix ! 😀

Thanks for the response.

This is how I invoked the container run :

docker run -i -t -h test.local -p 8080:80 mysite /bin/bash

which set the host to test.local and provided a bash for inspecting.

Thanks !

 

Link to post
Share on other sites
1 minute ago, ajoo said:

the www gets appended by self even when i type test.local in the browser.

Weird that the browser decided that it would take what you typed in and then do something else instead.

Is there anything else you did differently from the example? Any redirects in place?

5 minutes ago, ajoo said:

I tried using localhost before I came this route. That gave the same results.

Did you read the part in the example that talked about port mappings?

4 minutes ago, ajoo said:

Also I used test.local because the command "apachectl start" gave the warning something like not fully defined server hostname or sth.

No hostname means it should handle requests for every hostname. It's not a proper setup, thus the warning.

Link to post
Share on other sites

Hi,

Sorry for the delay.

So I ran it using

docker run -p 8080:80 -d mysite

 and the browser at localhost and got the following page

Quote

Unable to connect

Firefox can’t establish a connection to the server at localhost.

    The site could be temporarily unavailable or too busy. Try again in a few moments.
    If you are unable to load any pages, check your computer’s network connection.
    If your computer or network is protected by a firewall or proxy, make sure that Firefox is permitted to access the Web.

 So I ran it interactive and it is  still the same.

apachectl start, restart or apache2ctl -D FOREGROUND gives the following error:

Quote

root@7cf769d95922:~# apache2ctl -D FOREGROUND
AH00558: apache2: 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

apachectl status gives

Quote

Looking up localhost
Making HTTP connection to localhost
Alert!: Unable to connect to remote host.

lynx: Can't access startfile http://localhost/server-status
'www-browser --dump http://localhost:80/server-status' failed.
Maybe you need to install a package providing www-browser or you
need to adjust the APACHE_LYNX variable in /etc/apache2/envvars

So the problem seems to be somewhere here. I am googling for the solution. In case you have help, would be great !

Thanks !

 

Link to post
Share on other sites

Hi, 

I know it allows the container to communicate with the host by mapping the container port 8080 to host port 80.  But how does that link up to this ? I thought it to do with the settings of environment variables  related to lynx as that's what google look-ups suggest. 

A better hint from you maybe might do the trick. 🙂

Thanks. 

 

Link to post
Share on other sites
1 hour ago, ajoo said:

I know it allows the container to communicate with the host by mapping the container port 8080 to host port 80.

Try again. And pay very close attention to what you read.

Hint: What port does the Dockerfile say it will be exposing?

Link to post
Share on other sites

Internally it exposes the 8080 on the container which is mapped to port 80 on the host. So simply a localhost should be working provided the container does not exit as soon as it starts. However the container status is exited unless in the interactive mode. If the container would be UP and not exited, I would think it maybe a network / port issue but since it's exited I feel the issue may lie else where. 

So what do you say. Thanks.

 

Link to post
Share on other sites

I might have said ir wrong though above, port 80 in the container maps to port 8080 on the host which means I would need to access localhost using :8080 provided the container is not exited. I have tried it in the interactive mode to no avail. I get the same page. Please help resolve. Thanks.

Link to post
Share on other sites
2 hours ago, ajoo said:

I might have said ir wrong though above, port 80 in the container maps to port 8080 on the host which means I would need to access localhost using :8080 provided the container is not exited.

That's it. "-p X:Y" maps the host's X to the container's Y.

Make sure the container (and Apache) is running, and that you're browsing to localhost:8080. You should definitely get a connection, even if something else doesn't work.

  • Great Answer 1
Link to post
Share on other sites

So eventually after a loads of tries on my existing image,  I finally removed all the containers, images from my host and rebuilt the container again.  To my utter delight, the status on the container showed UP !!!!!!!!!!! 😇

This time it ran straight away !! I think the image was corrupted somewhere and the container always was in the exited state immediately after going UP. Thank you very much requinix for that insight into the -p switch and to finally get this working.

Thanks loads !🙏

 

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.