java.net.UnknownHostException: postgres

Dhanraj

I am trying to deploy spring boot application on kubernetes and connect to postgres which is on my localhost.

Spring boot deployment is fine. for postgres i did as

kind: Service
apiVersion: v1
metadata:
  name: postgres
  namespace: default
spec:
  type: ExternalName
  # https://docs.docker.com/docker-for-mac/networking/#use-cases-and-workarounds
  externalName: host.docker.internal
  ports:
    - name: port
      port: 5432

kubectl get svc gives

postgres           ExternalName   <none>           host.docker.internal   5432/TCP         9m13s

I am database url as

jdbc:postgresql://postgres:5432/postgres

So spring boot deployed logs give exception as

 java.net.UnknownHostException: postgres
A_Suh

This feature works only for Mac and Win Docker, so if you are running it on Linux -it's not gonna work.

Linux support for this hostname has been implemented and is likely coming in the next days/weeks: docker/libnetwork#2348

There are still some workarounds, while it's not released for Linux

I. you can create a file named .ddev/docker-compose.xdebug.yaml in your project with these contents:

# For Linux users; Docker has not yet supported the "host.docker.internal"
# convention that is used in ddev v0.18.0. But if you add this file as
# .ddev/docker-compose.xdebug.yaml it should sort that out.
# Note that the IP address in your environment might not be 172.17.0.1,
# Find out what address to use with "ifconfig docker0" or "ip addr show docker0 | grep inet"
version: "3"
services:
  web:
    extra_hosts:
      # Find out what address to use with "ifconfig docker0" or "ip addr show docker0 | grep inet"
      - "host.docker.internal:172.17.0.1"

II. Use this image to forward TCP and UDP traffic to the docker host

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

java.net.UnknownHostException on Docker

java.net.UnknownHostException error in InetAddress

java.net.UnknownHostException: Name or service not known

java.net.UnknownHostException on file:// method

java.net.UnknownHostException harvest Dspace collection

java.net.UnknownHostException spring ,zuul ,eureka

Websphere 8.5 - java.net.UnknownHostException

Error: -copyFromLocal: java.net.UnknownHostException

java.net.UnknownHostException Cannot create socket. Java

Java: InetAddress.getLocalHost(); throws java.net.UnknownHostException

java.lang.IllegalArgumentException: java.net.UnknownHostException: tmp

Error java.net.UnknownHostException while connecting Cassandra cluster

redis.clients.jedis.exceptions.JedisConnectionException: java.net.UnknownHostException

java.net.UnknownHostException dockerized mysql from spring boot application

How to handle java.net.UnknownHostException while using retrofit

Caused by: java.net.UnknownHostException: host.docker.internal

"hadoop namenode -format" returns a java.net.UnknownHostException

Clicking through to new site returns error "java.net.UnknownHostException:"

Apache httpcomponent returns java.net.UnknownHostException: Name or service not known

Keycloak docker container throws `java.net.UnknownHostException` during startup

Got "java.net.UnknownHostException: spark-master" in cluster mode

java.net.UnknownHostException: Invalid hostname for server: local

Android java.net.UnknownHostException: Host is unresolved (strategy question)

java.net.UnknownHostException Can't Solve in selenium

Hadoop: java.net.UnknownHostException: hadoop-slave-2

java.net.UnknownHostException: api.sandbox.amazon.co.jp

java.net.UnknownHostException error although there is a valid connection the to website

android java.net.UnknownHostException: Unable to resolve host

java.net.UnknownHostException: Unable to resolve host "": No address associated with hostname