将本地 NodeJS 应用程序连接到Docker Oracle数据库

sauutmhj  于 2022-09-19  发布在  Docker
关注(0)|答案(1)|浏览(256)

我正在尝试将本地NodeJS应用程序连接到Docker容器中的Oracle数据库。这是我的index.js

  1. const express = require('express');
  2. const oracledb = require('oracledb');
  3. const app = express();
  4. oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
  5. async function conexion(){
  6. let conexion;
  7. try{
  8. conexion = await oracledb.getConnection({
  9. user :"myuser",
  10. password :"123456",
  11. connectString :"172.17.0.2/ORCLCDB" //this is the IP of the docker container
  12. });
  13. const data = await conexion.execute(
  14. 'SELECT * FROM Pais',
  15. );
  16. console.log(data.rows);
  17. } catch(err){
  18. console.error(err);
  19. }
  20. }
  21. app.use(express.json());
  22. var port = process.env.PORT || 8080
  23. conexion();
  24. app.listen(port)
  25. console.log('API escuchando en el puerto ' + port)

但在运行我的NodeJS应用程序时,我收到以下错误:

  1. API escuchando en el puerto 8080
  2. Error: DPI-1047: Cannot locate a 64-bit Oracle Client library: "libclntsh.so: cannot open shared object file: No such file or directory". See https://oracle.github.io/node-oracledb/INSTALL.html for help
  3. Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
  4. You must have 64-bit Oracle Client libraries configured with ldconfig, or in LD_LIBRARY_PATH.
  5. If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
  6. https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
  7. at processTicksAndRejections (internal/process/task_queues.js:95:5)
  8. at async conexion (/home/pedrocastro/Universidad/2S-2022/BASES1/Proyecto1_API/index.js:11:20) {
  9. errorNum: 0,
  10. offset: 0
  11. }

我怎么才能解决这个问题??

wfypjpf4

wfypjpf41#

我两天来一直在尝试同样的事情。我找到了这样的解决方案。

首先,我们将自己的本地项目作为停靠容器运行,并将所有正在运行的容器(Oracledb)与停靠合成文件network_mode: bridge连接起来。通过这种方式,他们可以相互交流。

该项目无法运行的原因是:Docker容器没有在我们的本地主机上运行。你可以把它想象成在docker内部运行的独立计算机,它们之间没有连接。

相关问题