我正在尝试将本地NodeJS应用程序连接到Docker容器中的Oracle数据库。这是我的index.js
const express = require('express');
const oracledb = require('oracledb');
const app = express();
oracledb.outFormat = oracledb.OUT_FORMAT_OBJECT;
async function conexion(){
let conexion;
try{
conexion = await oracledb.getConnection({
user :"myuser",
password :"123456",
connectString :"172.17.0.2/ORCLCDB" //this is the IP of the docker container
});
const data = await conexion.execute(
'SELECT * FROM Pais',
);
console.log(data.rows);
} catch(err){
console.error(err);
}
}
app.use(express.json());
var port = process.env.PORT || 8080
conexion();
app.listen(port)
console.log('API escuchando en el puerto ' + port)
但在运行我的NodeJS应用程序时,我收到以下错误:
API escuchando en el puerto 8080
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
Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html
You must have 64-bit Oracle Client libraries configured with ldconfig, or in LD_LIBRARY_PATH.
If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from
https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async conexion (/home/pedrocastro/Universidad/2S-2022/BASES1/Proyecto1_API/index.js:11:20) {
errorNum: 0,
offset: 0
}
我怎么才能解决这个问题??
1条答案
按热度按时间wfypjpf41#
我两天来一直在尝试同样的事情。我找到了这样的解决方案。
首先,我们将自己的本地项目作为停靠容器运行,并将所有正在运行的容器(Oracledb)与停靠合成文件
network_mode: bridge
连接起来。通过这种方式,他们可以相互交流。该项目无法运行的原因是:Docker容器没有在我们的本地主机上运行。你可以把它想象成在docker内部运行的独立计算机,它们之间没有连接。