ORA-12545 When running Oracle inside Docker
When trying to make an http request from my Oracle database running inside a Docker container, I received the following error:
SQL> select utl_http.request('http://api.open-notify.org/iss-now.json') from dual; Error starting at line : 1 in command - select utl_http.request('http://api.open-notify.org/iss-now.json') from dual Error report - ORA-29273: HTTP request failed ORA-06512: at "SYS.UTL_HTTP", line 1722 ORA-12545: Connect failed because target host or object does not exist ORA-06512: at line 1
This puzzled me quite a bit. The error pretty much says that it cannot resolve the hostname api.open-notify.org. When I run a simple curl command from my host, I get the expected result.
$ curl http://api.open-notify.org/iss-now.json {"message": "success", "iss_position": {"longitude": "-144.6590", "latitude": "-36.9405"}, "timestamp": 1531175688}[oracle@jcat-server sh]
Then it dawned on me to try the curl command from within the container:
docker exec -it 76f4 curl http://api.open-notify.org/iss-now.json curl: (6) Could not resolve host: api.open-notify.org
So it was the container that could not resolve the domain name.
After some research, I found that I need to run the docker image with the –dns parameter, which tells the container where to do DNS lookups. You can add multiple –dns parameters to your run command. I used it with Google’s DNS server and the one specified in my /etc/resolv.conf file. So the run command looks something like this:
docker run -d \ -p 1521:1521 \ -v /u01/oradata/xe:/u01/app/oracle \ --dns "some.ip.address.169" \ --dns "8.8.8.8" \ --name oracle_xe \ sath89/oracle-xe-11g
When I now try the curl command to test, I get the correct response:
$ docker exec -it 1234 curl http://api.open-notify.org/iss-now.json {"message": "success", "iss_position": {"longitude": "-73.8368", "latitude": "-49.7166"}, "timestamp": 1531176511}
Now trying it from inside the database, works, too:
SQL> select utl_http.request('http://api.open-notify.org/iss-now.json') from dual; UTL_HTTP.REQUEST('HTTP://API.OPEN-NOTIFY.ORG/ISS-NOW.JSON') {"message": "success", "iss_position": {"longitude": "-67.2304", "latitude": "-48.1655"}, "timestamp": 1531176585}
BTW: Don’t forget to set your ACL!