nha
nha

Reputation: 18005

docker-compose use extra_hosts with container id

I have a dockerized app that needs to talk to an external (not dockerized) oracle database.

The app works on my local machine only if I append the result of the hostname command to the localhost entry in my /etc/hosts file. Otherwise I get an error from the OracleDB driver:

Caused by: oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12514, TNS:listener does not currently know of service requested in connect descriptor

I could log in my container and edit /etc/hosts manually, I would like to avoid this manual step after rebuilding. How do I keep this file up to date?

Furthermore it seems the hostname set by docker is the container id.

Is there a way to reference a container id from inside the docker-compose.yml file?

Upvotes: 1

Views: 1697

Answers (2)

rdm
rdm

Reputation: 688

turns out hostname: is not used for networking in other containers.

Upvotes: 0

ilyapt
ilyapt

Reputation: 1829

Maybe easily way is set specific hostname for container?

Set hostname: foo in your docker-compose file and then use hostname foo instead hosname based on docker id.

Upvotes: 2

Related Questions