I have a Debian server with apache2 on it. I can access it by an ip address.
What I want is to be able to access to the containers in it (which contain an apache2 serveur) from the outside by an url like "myIpAddress/container1". What I currently have is an acces to those containers only from the Debian server.
I thought about using proxy reverse, but I cannot make it works.
Thank you for your help! :-)
Map the docker container's port to a host port and access the docker container from <host-ip>:port.
docker run -p host-port:container-port image
For example, upon running a container using the above command will make the container available at 127.0.0.1
docker run -p 80:5000 training/webapp
Update:
Setting up reverse proxy using NGINX
This example uses a plain NGINX container as site A and plain Apache server as site B.
Run the reverse proxy.
docker run -d \
--name nginx-proxy \
-p 80:80 \
-v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy
Start the container for site A, specifying the domain name in the VIRTUAL_HOST variable.
docker run -d --name site-a -e VIRTUAL_HOST=a.example.com nginx
Check out your website at http://a.example.com.
With site A still running, start the container for site B.
docker run -d --name site-b -e VIRTUAL_HOST=b.example.com httpd
Check out site B at http://b.example.com.
Note: Make sure you have set up DNS to forward the subdomains to the host running nginx-proxy. If you're using AWS, the easiest way is to use Route53.
For testing locally, map sub-domains to resolve to localhost by adding entries in /etc/hosts file.
127.0.0.1 a.example.com
127.0.0.1 b.example.com
References
jwilder NGNIX Proxy Github
NGNIX reverse proxy using docker
Related
I am starting out with Apache webservices. I am running it on Docker with the httpd image, and I have mapped host machine port 81 to 80 on the container.
I have created a new index.html which I want to test as my new home page, but at a loss as to how to upload it to the server.
I'm not aware of any GUI type methods, but in any case would prefer a programmatic approach.
I have tried using curl commands (trial and error of a few variations). One example is:
curl -u root -XPUT -H "content-type: application/html" #index.html http://localhost:81/index.html
Sometimes the existing index.html is returned, other times I get Error 405: Method Not Allowed.
Use docker cp
docker cp ./index.html container:/var/www/html/index.html
Adapt paths to your needs; to obtain container name, run docker ps . If your container is named apache2, then full command will be:
docker cp ./index.html apache2:/var/www/html/index.html
I have installed FaxServer to my Ubuntu server. It uses DOCKER.
It is up and running as follows:
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS NAMES
597d61ce2785 bludesign/faxserver:latest "/bin/sh -c 'bash -c…" 19
minutes ago Up 5 minutes 0.0.0.0:8080->8080/tcp faxserver_vapor_1
6595fe5908c5 mongo:latest "docker-entrypoint.s…" 19
minutes ago Up 6 minutes 27017/tcp faxserver_mongo_1
I do not have access to apply any public IP numbers to the DOCKER. My main server in which DOCKER is running has access to the internet and hence has a public ip.
How can I run apache or something to access the FaxServer from the internet running on 0.0.0.0:8080? The mongo is part of the FaxServer.
Any guidance much appreciated.
There are two options:
You can use NGINX as a reverse proxy server (https://github.com/jwilder/nginx-proxy), and add an env-var called "virtual-host" to the container as follows:
docker run -d -p 80808:8080 -e VIRTUAL_HOST=awesomefaxservice.com --name awesomefaxservice bludesign/faxserver
then configure a DNS to point to the machine ip, Once you have done that any requests matching the virtual host will be redirected to the container on the exposed port.
If you don't want to install a proxy and get a dns, check option 2.
You can configure the system proxy rules to accept incoming traffic from the internet and simple access your_static_ip:container_port
I am not able to access my container which is running a “dockerized” ipython notebook application. The host is a CentOS7 running in Google Cloud.
Here is the details of the environment:
Host: CentOS7/Apache Webserver running for example on IP address: 123.4.567.890 (Port 80 is Listening)
Docker container: An Jupyter Notebook application – the container is called for example APP-PN and can be accessed via the port: 8888 in docker.
It I run the application at my local server I can access the notebook application via the browser:
http://localhost:8888/files/dir1/app.html
However, when I run the application on the Google Cloud if I put:
http://123.4.567.890:8888/files/dir1/app.html
I cannot access it.
I tried all combinations open the port 8888 via TCP on the host as well as to expose the port via the docker run command – all of which did not work:
firewall-cmd --zone=public --add-port=8888/tcp --permanent
docker run -it -p 80:8888 APP-PN
docker run --expose 8888 -it -p 80:8888 APP-PN
Also I tried to change Apache to Listen to port 80 and 8888 but I got some errors.
However if I STOP the Apache Webserver and then run the command
docker run -it -p 80:8888 APP-PN
I can access the application simply in my browser via:
htttp://123.4.567.890/files/dir1/app.html
HERE is my question: I do not want to STOP my Apache Webserver and at the same time I want to access my docker container via the external port 8888.
Thanks in advance for all the help.
I didn't see in your examples a
docker run -it -p 8888:8888 APP-PN
The -p argument describes first the host port to listen on and then the container port to route to. If you want the host to listen on the same port as the container, -p 8888:8888 will get it done.
I am new to Apache and docker. I am running httpd:2.4 image from docker hub. Httpd container is running fine. When I am hitting localhost from browser, it gives messages as "IT workes" but when i tried to hit localhost with https then it is giving error as site can not be reached.
command to run httpd
docker run -d -p 443:443 --name httpd httpd:2.4
You must configure ssl certificate for this. Please refer SSL/HTTPS section given on Docker Hub official doc
I didn't find something about running many different webapp-container on one host. So for example I have two containers. On the first I run an apache with owncloud and on the second I run a wordpress blog. Both of them have to run on port 80. How could I handle this?
Thanks
You can use -p flag to map ports:
docker run -p 8080:80 owncloud
docker run -p 8081:80 wordpress
And than access owncloud with http://yourdomain.com:8080/ and wordpress with http://yourdomain.com:8081/
It is common to combine docker with a reverse proxy like HAProxy.
With a reverse proxy you can pass request to owncloud.yourdomain.com to your owncloud container and from wordpress.yourdomain.com to the wordpress container. (or yourdomain.com/owncloud and yourdomain.com/wordpress)
You will have to use different ports in the host (otherwise you will get an error starting the second container).
To avoid that, expose one of the 80 internal port to another port in the host.
For instance, when running 'docker run':
docker run -p 8081:80 name_of_your_image
This will export the port 80 of your server in the port 8081 in the host.
if you want you can use docker-gen, it's a simple script where you can balance the docker with a simple environment variables (on container).
This is the documentation:
https://github.com/jwilder/docker-gen