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.
Related
i need to run an Nextcloud instance over an IPv6 Only Server.
(Web access will be accessable over IPv4 and IPv6 over an nginx reverse proxy).
Problem:
If i try to install an app to nextcloud, it tryt to curl it from https://github.com which is (what a shame today) not ipv6 compatible.
Error message:
cURL error 7: (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) for https://github.com/nextcloud-releases/calendar/releases/download/v4.2.0/calendar-v4.2.0.tar.gz
Setup:
Debian 11.6
Apache/2.4.54
PHP 8.1.13 (cli)
First approach:
I found public proxy services for github, that proxy the requests through an nginx, through edited entrys in the /etc/hosts file.
2a01:4f8:c010:d56::2 github.com 2a01:4f8:c010:d56::3 api.github.com 2a01:4f8:c010:d56::4 codeload.github.com 2a01:4f8:c010:d56::5 objects.githubusercontent.com
That solution works for me on console, but not for the nextcloud application.
It seems php-curl ignores the /etc/hosts file.
I also found "CURLOPT_RESOLVE" but it seems that something i need to put in the nextcloud code?
Is there anything similar i can put in the php.ini or something like that?
Question:
Is there any option to force php-curl to use the /etc/hosts file without touching the code of nextcloud?
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.
I need to create an apache server to host my files and to get them by ajax. So, I'm using docker to deploy my server.
My docker image is httpd:2.4.
I deployed the server with the following command :
docker run -p 80:80 -dit --name file-server \
-v /sources/docker/apache-server/www/:/usr/local/apache2/htdocs/ httpd:2.4
But when I want to make the request for ajax, this is the result:
XMLHttpRequest cannot load http://server/kml/example.kml. No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
So, I want to follow the next steps How to Enable CORS for Apache httpd server? (Step-By-Step Process). But I do not know how to add that command in the httpd.conf of the component. And I don't have the httpd.conf template to replace it with:
v /sources/docker/apache-server/my-httpd.conf:/usr/local/apache2/conf/httpd.conf
Please help me with this question.
You have that enter in shell-terminal with command docker exec -it nameContainer sh . write in terminal: su with those commands now you are root user in your Docker.
Now in terminal, you have than write a2enmod headers and restart your docker
The last command was for activate mod_header and just now you have that create a .htaccess in your project root file and write inside:
Header add Access-Control-Allow-Origin "*"
With that for me work fine and didn't need install apache in my machine
This has certainly already been addressed elsewhere and has many different solutions, however it's the first search hit for 'cors apache docker' so here's my 2 cents:
The best solution (because it is auditable and repeatable) is to use the apache docker image as a base for your own image using the docker build command and a Dockerfile. I won't go in to that as that's not the direct question here, but the basic bits are the same.
Create an "extra" apache config file with the CORS header bits:
me#mymachine:~$ docker exec file-server bash -c 'printf "<Directory \"/var/www/html\">\n Header set Access-Control-Allow-Origin \"*\"\n</Directory>\n" >> /usr/local/apache2/conf/httpd.conf'
me#mymachine:~$ docker exec file-server bash -c 'tail /usr/local/apache2/conf/extra/cors.conf'
<Directory "/var/www/html">
Header set Access-Control-Allow-Origin "*"
</Directory>
Restart apache to use this new config:
me#mymachine:~$ docker exec file-server bash -c 'apachectl -k restart'
NOTE: If you haven't configured a ServerName anywhere, then you might see this warning which is unrelated to the CORS configuration:
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.3. Set the 'ServerName' directive globally to suppress this message
I'm building a Docker-based Apache proxy, and I'd like the proxied port to be configurable.
I link the containers with --link ...:proxied, so Docker makes the environment variables PROXIED_PORT_80_TCP_ADDR and PROXIED_PORT_80_TCP_PORT. I used ProxyPass / "http://${PROXIED_PORT_80_TCP_ADDR}:${PROXIED_PORT_80_TCP_PORT}/" to reverse proxy to port 80.
I'd like the port to be configurable from the command line, when I start the container. I pass the variable as -e "PORT=...", and it is usable as ${PORT} in the Apache config.
I've tried to nest the variables, like ${PROXIED_PORT_${PORT}_TCP_ADDR} without success, and also using the Define plugin, but still no luck.
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.