PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, September 2, 2022

[FIXED] How can I remove the need for two docker containers which work together to use bridged networking?

 September 02, 2022     docker, nginx, nginx-reverse-proxy, postgresql, tomcat     No comments   

Issue

I have three docker containers:

1: nginx container accessible on port 8080 and not using bridged networking

2: xwiki container running tomcat accessible on port 8080 using bridged networking

3: Postgres container hosting the xwiki database and accessible on port 5432 using same bridged network as the xwiki container

I want to be able to set nginx to reverse proxy and load the xwiki site on a url such as http://site-root/xwiki but its not able to do this as its not on the same bridged network and I get a no route to host error...

All the hosts are accessible from a remote host using the docker hosts ip and the respective container port...

I have created xwiki and postgres containers that dont use bridged networking to test this but the xwiki tomcat server fails as xwiki cant find the postgres server and I get the below error as a tomcat exception:

java.net.UnknownHostException: postgres-db-server

Is there away to remove the need for using bridged networking for the xwiki and postgres containers and have them communicate using the docker hosts IP and their respective port numbers?

I'm thinking that I may need to edit the tomcat config in the xwiki container so that it points to the postgres server using the docker hosts IP and the postgres default port...

Can any one give me an idea of if this sounds like to right solution or if I am missing something with regard to the need for bridged networking?

I realise that a possible solution is to set the nginx container to use the same bridged networking but i also want the nginx service to be able to reverse proxy a node.js server running on the docker host... (not via docker)

Should I just containerise node and run all the containers using the same bridged network as this, logically should remove the problem, but I am concerned that it may cause other problems down the line...

The docker host is running on Centos 7

The commands used to manually run the containers as shown below:

Nginx

docker run -dti --name nginx-dev --hostname nginx-dev -p 80:80 -v /nginx/www:/usr/share/nginx/html:ro -v /nginx/conf:/etc/nginx -P -d nginx

Postgres

docker run --net=xwiki-nw --name postgres-db-server -p 5432:5432 -v /postgres/data:/var/lib/postgresql/data -e POSTGRES_ROOT_PASSWORD=xwiki -e POSTGRES_USER=xwiki -e POSTGRES_PASSWORD=xwiki -e POSTGRES_DB=xwiki -e POSTGRES_INITDB_ARGS="--encoding=UTF8" -d postgres:9.5

Xwiki

docker run --net=xwiki-nw --name xwiki -p 8080:8080 -v /xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=postgres-db-server xwiki:postgres-tomcat

Solution

Run

docker network connect xwiki nginx-dev 

And then you nginx container will be able to find the route to other two containers.



Answered By - Tarun Lalwani
Answer Checked By - Willingham (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing