I have Informix databases running in Docker containers. They have unpredictable published port numbers.
I am trying to connect from outside the container. Informix seems to want an entry in the sqlhosts file. I can create an ad hoc /tmp/sqlhosts.xxx
containing
mydbservername onsoctcp <container ip address> <servicename>
and use it with
INFORMIXSQLHOSTS=/tmp/sqlhosts.xxx /my.program
and my.program
connects to dbname@mydbservername
, I have verified this temporary sqlhosts file is being read and the mydbservername
is being discovered.
The error is
Cannot locate <servicename> service in /etc/services.
So far, so hacky, but it seems to work apart from the <servicename>
part. In static environments, this would match an entry in /etc/services
but I don't have write privileges for that file (and in any case, the dynamic port numbers would make it messy).
Ideally I would be able to connect to the database without going through a sqlhosts file at all -- the IP address and port number are known when I executemy.program
-- but there is a layer I don't control between my.program
and the database connection itself: I can only control the dbname@server
string, the userspace filesystem, and the environment variables.
How can I connect to an Informix database which manifests with an unpredictable IP/port?