Yes, it is possible. You can use the reverse proxy of web servers along with Docker's service discovery to achieve this.
Docker's service discovery basically works when you connect multiple docker containers to the same network such that you can access the containers by using container's hostname. The catch here is these containers must be connected to the same network.
Since you have mentioned that part of the application is Dockerized and lives on separate there are different solutions available.
Let us assume that:
- Nginx is the web server and it's running on server1.
- Dockerized App is in server2.
- Server1 and server2 can communicate with each other.
- You know Docker, Docker Swarm.
Using Docker Swarm and Service Discovery: *Recommended*
Create a docker swarm cluster and connect both the servers. Then create an overlay network. Once done run Nginx in server1 in the same network and run the dockerized app in server2 in the same network. Now you can use Nginx's proxy_pass
to connect to server2's docker app.
Using Docker and Port mapping:
Run the Dockerized app in server2 and map the ports by using docker port binding. In server1 use reverse proxy to connect to server2's mapped ports.
Note:
In both the case make sure
- Both server1 and server2 can communicate with each other.
- Open respective ports in the firewall as per the respective
documentation.
- You can also use other web servers like apache and the same steps can be followed.
Limitations: (Applicable only for Nginx reverse proxy)
Whenever the dockerized app is restarted Nginx's cache will not be refreshed hance it will throe 502 Bad Gateway error. In order to handle it, you may need to make Nginx refresh its cache once in particular interval. Refer to this answer of mine to know more details on how to do it.