Open a Docker Apache and PHP stack in Browser - apache

I am a Docker rookie who is stuck in configuration. I just wanted to build a docker Apache and PHP Stack with this guide:
Apache and PHP on Docker.
All seems worked except the problem that i don't know how to connect to my created docker container via browser IP/URL. Normally in Apache without Docker you just configure your /etc/hosts file with a ServerName and connect to it.
What is the solution with Docker?

When you run docker, you need to connect the host port with the apache port running inside your container.
This is done by adding -p 8000:80 where 8000 is your local port and 80 is the docker container port.
If you then connect to localhost:8000 you should see the response from apache in your docker container.

Related

Gitlab-ee external url is not working

I installed gitlab-ee on my ubuntu 16.04 server hosted with AWS. I am not able to launch gitlab using the external url that is mentioned in gitlab.rb file. I have apache as default webserver. I used a subdomain as external url. But when i launch that url, it is still landing on default apache page and not using nginx to launch gitlab. How to solve this issue?
Apache and Nginx will probably try to use the same ports (80 & 443). The first started, in your case Apache, will start normally, but the second will not initialize properly as two programs can not listen together on the same ports.
Confirm with the command sudo gitlab-ctl status nginx. This will return the status of the integrated nginx instance.
If it is stopped, stop apache and then start nginx using sudo gitlab-ctl start nginx.

Using docker bridge network IP to access vhost in apache container

I'd like to understand how I'm able to access a domain configured in a vhost inside a docker container by providing an entry in my local /etc/hosts file with the docker bridge network IP.
I use docker-compose (v2)
Docker network bridge IP (by default): 172.17.0.1
I have an apache container running on 172.19.0.10
Vhost is simple like :
<VirtualHost *:80>
ServerName mywebsite.local
In my local /etc/hosts file, I have : 172.17.0.1 mywebsite.local
And it works... but how ?
Is Docker using the port to guess where to forward the traffic (from 172.17.0.1 to 172.19.0.10) ?
Can someone give me with some explanations and if possible documentation ?
Thanks.
At some point you had to start your container/docker with something like this:
docker run -d -p 1337:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND
1337:80 means that localhost:1337 in your browser gets looked up on port 80, and therefore your apache-container.
Hopefully what you had in mind?!
Also see this or that.
You can try using
docker run -d --network=host <image> or in docker compose
network_mode: "host". Documentations on this can be found here.
Both of these put your container on top of the host network stacks.

Running apache in an ubuntu Docker container on a RedHat machine

I am new to Docker and have been trying to configure a standard default install of Apache2 running on the ubuntu:14.04 image.
This seems to work just fine when the Docker host machine is running Ubuntu, but when I try to run this same config on a machine running RHEL 6, I get apache config errors having to do with file permissions. Specifically, the default apache page returns a 403 forbidden page.
I thought the point of Docker was that I could create a container on one environment and it should behave exactly the same on any other environment.. am I way off?
Not 100% sure, but it may be that you need RHEL 7. From here you can:
docker pull rhscl/httpd-24-rhel7
See https://access.redhat.com/solutions/1378023

Run apache in both host machine and docker container on 80 port

I need to setup something like automated server setup using docker. Now server machine should support both docker or normal setups. So I need to setup apache web server on both docker container and host machine on 80 port. Like
Host Machine : application1.serverhost.com
Docker Machine : application2.serverdocker.com
But Docker will not utilize 80 port as it is already bind on host machine apache. While I am thinking of use reverse proxy on host machine with apache like
Proxy Setting -> 172.17.0.2:8080
while on browser connect to proxy application2.serverdocker.com on 80 port. IP -> 172.17.0.2 is docker container IP which I am thinking to get from docker inspect.
But if any other way to handle this in docker itself where I can ignore reverse proxy on host machine. And call both application1.serverhost.com and application2.serverdocker.com from browser without appending port.
EDIT : One big issue using reverse proxy is that whenever I need to add another docker on same server I need to add also proxy for that new IP too as that would also running docker apache on other port like 8081 than Host port:80 and first docker's port:8080. In other words lot of reverse proxy settings and ports in case of lot of docker instances.
If you are using a reverse proxy, (like an NGiNX), that means both your Apache servers must run on ports different from 80.
Only your NGiNX would run (on host directly for instance) on port 80, and would redirect to localhost_apache1:xxx and 172.17.0.2_apache2:yyy.
From the user perspective, both Apache would be seen "as if" they were running on port 80 themselves.

httpd running internally but not externally

I have a new server running CentOS, and it has httpd running on 192.168.1.100:80.
I can connect to my server through ssh on 192.168.1.100, but when I go to 192.168.1.100 in my browser, it says "Oops! Google Chrome could not connect to 192.168.1.100".
I also tried wget to see if that works, and here is where it gets interesting.
when I run:
wget 192.168.1.100
On my server it gets the index.html file as it should.
but when I run it on my laptop is says "Connecting to 192.168.1.100:80... failed: No route to host."
Does anyone know how to fix this?
Seems like your Apache configuration binds httpd to 192.168.1.100:80
Find line Listen 192.168.1.100:80 in Apache main configuration - something like /etc/httpd/httpd.conf or /etc/apache2/httpd.conf and change this line to Listen 0.0.0.0:80.
Restart Apache and it will probably work.