I have 2 docker containers. One for my spring-boot application and one for my Solr container.
I created a docker network so that both containers could run on the same network, and started both containers on it
docker network create mynetwork
docker run --name solr-container --network mynetwork -d -p 8983:8983 solr
docker run --name spring-app --network mynetwork -d -p 8080:8080 my-spring-boot-image
This is my Solr link inside spring app : spring.data.solr.host=http://solr-container:8983/solr/
Code to add document to Solr:
public void addDocument(String articleUUID, String articleUrl) throws Exception {
SolrInputDocument document = new SolrInputDocument();
document.addField("articleUUID", articleUUID);
document.addField("articleUrl", articleUrl);
solrClient.add("gendoi", document);
solrClient.commit("gendoi");
}
I've added a try-catch block when calling this function:
try {
System.out.println("Trying to add document to Solr");
solrService.addDocument(articleUUID, articleDto.getUrl());
System.out.println("Document added successfully!");
} catch (Exception e) {
System.out.println("Error while adding document to Solr: " + e.getMessage());
throw new RuntimeException(Constants.ERROR_ADDING_SOLR);
}
Both of these containers are running on the same network. However, when I run my spring container and try to add document to Solr, it is giving me error that could not add document to Solr. Moreover, none of the logs are being displayed, such as "Trying to add Solr". When I run my spring application on my computer instead of through docker container however, the Solr code works properly and document gets added.
Why is this not working when I try to add it through the Docker Spring container?
The implementation of docker was correct.
The issue I was facing was due to docker creating wrong image of my spring app.
If I run both images on the same network, they are able to communicate with each other now!