Reputation: 37
I am new to docker and I ran into an architectural problem: I have two sets of container (CUSTOMER1, CUSTOMER2) running in my computer by the same docker-compose file which, both, contains two same applications (APP1, APP2).
My question is: Is there a way, using an nginx server in the same host, to access to the desired app in the desired container (ex: APP1 into CUSTOMER1 container by browser link (ex: CUSTOMER1.MYPC.IT/APP1) through my computer using Windows containers?
Here I attach a graphical representation for better explaination:
Here, is the nginx.conf file from the nginx container:
worker_processes auto;
events {
worker_connections 4096;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 99999;
server {
listen 80;
server_name localhost 127.0.0.1;
resolver 127.0.0.11;
location /APP1 {
proxy_pass http://test_app1/......;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_send_timeout 300;
}
location /APP2 {
include /etc/nginx/mime.types;
proxy_pass http://test_app2/......;
proxy_set_header X-Forwarded-For $remote_addr;
}
}
}
Here, is my Docker-compose file:
version: '3.9'
services:
app1basecontainer:
image: app1baseimg
build: ./APP1BASEIMG
volumes:
- apps1hared:C:\DEFAULT\APPPortal
expose:
- 8080
app2basecontainer:
depends_on:
- "appbasecontainer"
image: app2baseimg
build: ./APP2BASEIMG
volumes:
- apps2hared:C:\DEFAULT\APPPortal
expose:
- 80
volumes:
apps1hared:
apps2shared:
Thanks so much
Upvotes: 2
Views: 1621
Reputation: 2873
2 Options:
1- Bind container ports to outside, then proxy to them:
services:
app1basecontainer:
...
ports:
- 8080:8080
app2basecontainer:
...
ports:
- 80:80
Then, in your Nginx conf:
server{
location /APP1 {
proxy_pass http://localhost:8080;
}
location /APP2 {
proxy_pass http://localhost:80;
}
}
2- Nginx container to your docker-compose, then apps and nginx are in the same network, and nginx can see apps containers. Then your nginx conf changes to :
server{
location /APP1 {
proxy_pass http://CONTAINER_NAME:8080;
}
location /APP2 {
proxy_pass http://CONTAINER_NAME:80;
}
}
Upvotes: 1