Skip to content

Commit 3543737

Browse files
committed
Add doc on installing in Docker
1 parent 47475d7 commit 3543737

File tree

2 files changed

+265
-10
lines changed

2 files changed

+265
-10
lines changed

INSTALL.md

Lines changed: 262 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ limitations under the License.
4040
- 3.11.1 [Copying node-oracledb Binaries on Windows](#winbins)
4141
- 3.12 [Installing Node.js and Node-oracledb RPMs from yum.oracle.com](#instnoderpms)
4242
- 3.13 [Building and Hosting your own node-oracledb Packages](#selfhost)
43+
- 3.14 [Using node-oracledb in Docker](#docker)
4344
4. [Installing Older Versions of Node-oracledb](#installingoldvers)
4445
- 4.1 [Installing node-oracledb 2.x and 3.x](#installingv2)
4546
- 4.2 [Installing node-oracledb 1.x](#installingv1)
@@ -1425,6 +1426,255 @@ or your `package.json` would contain:
14251426
. . .
14261427
```
14271428

1429+
### <a name="docker"></a> 3.14 Using node-oracledb in Docker
1430+
1431+
[Docker][59] allows applications to be containerized. Each application will
1432+
have a `Dockerfile` with steps to create a Docker image. Once created, the
1433+
image can be shared and run.
1434+
1435+
#### Installing Node.js in Docker
1436+
1437+
If your `Dockerfile` uses Oracle Linux:
1438+
1439+
```
1440+
FROM oraclelinux:7-slim
1441+
```
1442+
1443+
Then you can install Node.js from [yum.oracle.com][46] using:
1444+
1445+
```
1446+
RUN yum -y install oracle-release-el7 oracle-nodejs-release-el7 && \
1447+
yum-config-manager --disable ol7_developer_EPEL && \
1448+
yum -y install nodejs && \
1449+
rm -rf /var/cache/yum
1450+
```
1451+
1452+
Alternatively you may prefer to use a [Node.js image from
1453+
Docker Hub][56], for
1454+
example using:
1455+
1456+
```
1457+
FROM node:12-buster-slim
1458+
```
1459+
1460+
#### Installing Instant Client in Docker
1461+
1462+
Review the [Oracle Technology Network][12] or the [Oracle Linux 7][51] channel
1463+
for the latest Instant Client package available.
1464+
1465+
1. Using Oracle Linux Instant Client RPMs
1466+
1467+
If you have an Oracle Linux image:
1468+
1469+
```
1470+
FROM oraclelinux:7-slim
1471+
```
1472+
1473+
Then you can install Instant Client RPMs:
1474+
1475+
```
1476+
RUN yum -y install oracle-release-el7 && \
1477+
yum-config-manager --enable ol7_oracle_instantclient && \
1478+
yum -y install oracle-instantclient19.3-basiclite && \
1479+
rm -rf /var/cache/yum
1480+
```
1481+
1482+
2. Automatically downloading the Instant Client zip File
1483+
1484+
Use an Instant Client zip file on Debian-based operating systems.
1485+
1486+
You can script the download of the Instant Client package during image
1487+
creation. To use the latest available Instant Client:
1488+
1489+
```
1490+
RUN wget https://download.oracle.com/otn_software/linux/instantclient/instantclient-basiclite-linuxx64.zip && \
1491+
unzip instantclient-basiclite-linuxx64.zip && rm -f instantclient-basiclite-linuxx64.zip && \
1492+
cd /opt/oracle/instantclient* && rm -f *jdbc* *occi* *mysql* *jar uidrvci genezi adrci && \
1493+
echo /opt/oracle/instantclient* > /etc/ld.so.conf.d/oracle-instantclient.conf && ldconfig
1494+
```
1495+
1496+
The `libaio` or `libaio1` package will need to be added manually.
1497+
1498+
On Oracle Linux
1499+
1500+
```
1501+
RUN yum install -y libaio
1502+
```
1503+
1504+
On a Debian-based Linux:
1505+
```
1506+
RUN apt-get update && apt-get install -y libaio1
1507+
```
1508+
1509+
3. Copying Instant Client zip files from the host
1510+
1511+
Download the Instant Client Basic Light Zip file, extract it, and remove
1512+
unnecessary files. The resulting directory can be added during image
1513+
creation. For example, with Instant Client Basic Light 19.3, the host
1514+
computer (where you run Docker) could have a directory `instantclient_19_3`
1515+
with these files:
1516+
1517+
```
1518+
libclntshcore.so.19.1
1519+
libclntsh.so.19.1
1520+
libipc1.so
1521+
libmql1.so
1522+
libnnz19.so
1523+
libociicus.so
1524+
```
1525+
1526+
With this, your Dockerfile could contain:
1527+
1528+
```
1529+
ADD instantclient_19_3/* /opt/oracle/instantclient_19_3
1530+
RUN echo /opt/oracle/instantclient_19_3 > /etc/ld.so.conf.d/oracle-instantclient.conf && \
1531+
ldconfig
1532+
```
1533+
1534+
The `libaio` or `libaio1` package will be needed, as shown in the previous option.
1535+
1536+
#### Installing node-oracledb and your application
1537+
1538+
Include node-oracledb as a normal dependency in your application `package.json` file:
1539+
1540+
```
1541+
. . .
1542+
"scripts": {
1543+
"start": "node server.js"
1544+
},
1545+
"dependencies": {
1546+
"oracledb" : "^4"
1547+
},
1548+
. . .
1549+
```
1550+
1551+
The `packge.json` and application file can be added to the image, and
1552+
dependencies installed when the image is built:
1553+
1554+
```
1555+
WORKDIR /myapp
1556+
ADD package.json /myapp/
1557+
ADD server.js /myapp/
1558+
RUN npm install
1559+
1560+
CMD exec node server.js
1561+
```
1562+
1563+
#### Using Oracle Net configuration files and Oracle Wallets
1564+
1565+
[Optional Oracle Net Configuration][58] files (like `tnsnames.ora` and
1566+
`sqlnet.net`) and files that need to be secured such as [Oracle wallets][57] can
1567+
be mounted at runtime using a Docker volume. Map the volume to the
1568+
`network/admin` subdirectory of Instant Client so the `TNS_ADMIN` environment
1569+
variable does not need to be set. For example, when the Wallet or configuration
1570+
files are in `/OracleCloud/wallet/` on the host computer, and the image uses
1571+
Instant Client 19.3 RPMs, then you can mount the files using:
1572+
1573+
```
1574+
docker run -v /OracleCloud/wallet:/usr/lib/oracle/19.3/client64/lib/network/admin:Z,ro . . .
1575+
```
1576+
1577+
The `Z` option is needed when SELinux is enabled.
1578+
1579+
#### <a name="dockerexample"></a> Example Application in Docker
1580+
1581+
This example consists of a `Dockerfile`, a `package.json` file with the
1582+
application dependencies, a `server.js` file that is the application, and an
1583+
`envfile.list` containing the database credentials as environment variables. It
1584+
is based on Oracle Linux.
1585+
1586+
The example `Dockerfile` is:
1587+
1588+
```
1589+
FROM oraclelinux:7-slim
1590+
1591+
RUN yum -y install oracle-release-el7 oracle-nodejs-release-el7 && \
1592+
yum-config-manager --disable ol7_developer_EPEL --enable ol7_oracle_instantclient && \
1593+
yum -y install nodejs oracle-instantclient19.3-basiclite && \
1594+
rm -rf /var/cache/yum
1595+
1596+
WORKDIR /myapp
1597+
ADD package.json /myapp/
1598+
ADD server.js /myapp/
1599+
RUN npm install
1600+
1601+
CMD exec node server.js
1602+
```
1603+
1604+
The `package.json` is:
1605+
1606+
```
1607+
{
1608+
"name": "test",
1609+
"version": "1.0.0",
1610+
"private": true,
1611+
"description": "Docker Node.js application",
1612+
"scripts": {
1613+
"start": "node server.js"
1614+
},
1615+
"keywords": [
1616+
"myapp"
1617+
],
1618+
"dependencies": {
1619+
"oracledb" : "^4"
1620+
},
1621+
"author": "Me",
1622+
"license": "UPL"
1623+
}
1624+
```
1625+
1626+
The application `server.js` contains:
1627+
1628+
```javascript
1629+
. . .
1630+
connection = await oracledb.getConnection({
1631+
user: process.env.NODE_ORACLEDB_USER,
1632+
password: process.env.NODE_ORACLEDB_PASSWORD,
1633+
connectString: process.env.NODE_ORACLEDB_CONNECTIONSTRING
1634+
});
1635+
const result = await connection.execute(
1636+
`SELECT TO_CHAR(CURRENT_DATE, 'DD-Mon-YYYY HH24:MI') AS D FROM DUAL`,
1637+
[],
1638+
{ outFormat: oracledb.OUT_FORMAT_OBJECT }
1639+
);
1640+
console.log(result);
1641+
. . .
1642+
```
1643+
1644+
The environment variables in `envfile.list` are used at runtime. The file
1645+
contains:
1646+
1647+
```
1648+
NODE_ORACLEDB_USER=hr
1649+
NODE_ORACLEDB_PASSWORD=<hr password>
1650+
NODE_ORACLEDB_CONNECTIONSTRING=server.example.com/orclpdb1
1651+
```
1652+
1653+
The image can be built:
1654+
1655+
```
1656+
docker build -t nodedoc .
1657+
1658+
```
1659+
1660+
Alternatively, if you are behind a firewall, you can pass proxies when building:
1661+
1662+
```
1663+
docker build --build-arg https_proxy=http://myproxy.example.com:80 --build-arg http_proxy=http://www-myproxy.example.com:80 -t nodedoc .
1664+
```
1665+
1666+
Finaly, a container can be run from the image:
1667+
1668+
```
1669+
docker run -ti --name nodedoc --env-file envfile.list nodedoc
1670+
```
1671+
1672+
The output is like:
1673+
1674+
```
1675+
{ metaData: [ { name: 'D' } ],
1676+
rows: [ { D: '24-Nov-2019 23:39' } ] }
1677+
```
14281678

14291679
## <a name="installingoldvers"></a> 4. Installing Older Versions of Node-oracledb
14301680

@@ -1546,7 +1796,7 @@ Issues and questions about node-oracledb can be posted on [GitHub][10] or
15461796

15471797
[1]: http://oracle.github.io/node-oracledb/
15481798
[2]: https://www.python.org/downloads/
1549-
[3]: http://www.oracle.com/technetwork/database/database-technologies/instant-client/overview/index.html
1799+
[3]: https://www.oracle.com/database/technologies/instant-client.html
15501800
[4]: https://www.npmjs.com/package/oracledb
15511801
[5]: https://blogs.oracle.com/opal/getting-a-c11-compiler-for-node-4,-5-and-6-on-oracle-linux-6
15521802
[6]: https://support.oracle.com/epmos/faces/DocumentDisplay?id=207303.1
@@ -1555,8 +1805,8 @@ Issues and questions about node-oracledb can be posted on [GitHub][10] or
15551805
[9]: https://www.github.com/oracle/odpi
15561806
[10]: https://github.com/oracle/node-oracledb/issues
15571807
[11]: http://nodejs.org
1558-
[12]: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html
1559-
[13]: http://www.oracle.com/technetwork/topics/linuxx86-64soft-092277.html#ic_x64_inst
1808+
[12]: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html
1809+
[13]: https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html#ic_x64_inst
15601810
[14]: https://linux.oracle.com
15611811
[15]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-7F967CE5-5498-427C-9390-4A5C6767ADAA
15621812
[16]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=GUID-2041545B-58D4-48DC-986F-DCC9D0DEC642
@@ -1565,15 +1815,15 @@ Issues and questions about node-oracledb can be posted on [GitHub][10] or
15651815
[19]: https://github.com/oracle/node-oracledb/tree/master/examples
15661816
[20]: https://www.oracle.com/database/technologies/appdev/xe.html
15671817
[21]: https://blogs.oracle.com/opal/the-easiest-way-to-install-oracle-database-on-apple-mac-os-x
1568-
[22]: http://www.oracle.com/technetwork/topics/intel-macsoft-096467.html
1818+
[22]: https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html
15691819
[23]: https://docs.oracle.com/database/
15701820
[24]: https://www.oracle.com/pls/topic/lookup?ctx=dblatest&id=NTCLI
1571-
[25]: http://www.oracle.com/technetwork/topics/winx64soft-089540.html
1572-
[26]: http://www.oracle.com/technetwork/topics/winsoft-085727.html
1821+
[25]: https://www.oracle.com/database/technologies/instant-client/winx64-64-downloads.html
1822+
[26]: https://www.oracle.com/database/technologies/instant-client/microsoft-windows-32-downloads.html
15731823
[27]: https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads
15741824
[29]: https://www.microsoft.com/en-us/download/details.aspx?id=3387
1575-
[30]: http://www.oracle.com/technetwork/topics/aix5lsoft-098883.html
1576-
[31]: http://www.oracle.com/technetwork/topics/solx8664soft-097204.html
1825+
[30]: https://www.oracle.com/database/technologies/instant-client/aix-ppc64-downloads.html
1826+
[31]: https://www.oracle.com/database/technologies/instant-client/solx8664-downloads.html
15771827
[32]: https://github.com/oracle/node-oracledb/blob/v1.13.1/INSTALL.md
15781828
[40]: https://github.com/oracle/node-oracledb/tags
15791829
[41]: https://github.com/oracle/node-oracledb/releases
@@ -1591,3 +1841,7 @@ Issues and questions about node-oracledb can be posted on [GitHub][10] or
15911841
[53]: https://nodejs.org/api/n-api.html
15921842
[54]: https://github.com/oracle/node-oracledb/blob/v3.0.1/INSTALL.md
15931843
[55]: https://github.com/oracle/node-oracledb/blob/v3.1.2/INSTALL.md
1844+
[56]: https://hub.docker.com/_/node/
1845+
[57]: https://oracle.github.io/node-oracledb/doc/api.html#connectionadb
1846+
[58]: https://oracle.github.io/node-oracledb/doc/api.html##tnsadmin
1847+
[59]: https://www.docker.com/

doc/api.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14390,7 +14390,8 @@ Oracle Linux.
1439014390
To get a free database hosted in Oracle Cloud, see [Oracle Cloud Free
1439114391
Tier][162]. If you want to use your own database, installing the free [Oracle
1439214392
Database 'XE' Express Edition][130] is quick and easy. Other database editions
14393-
may be downloaded [here][154] or [used with Docker][155].
14393+
may be downloaded [here][154]. Dockerfiles for Oracle Database and Oracle
14394+
Instant Client are on [github.com/oracle/docker-images][155].
1439414395

1439514396
If you want to install Oracle Linux yourself, it is free from [here][156].
1439614397

@@ -14551,7 +14552,7 @@ can be asked at [AskTom][158].
1455114552
[152]: https://www.oracle.com/technetwork/community/developer-vm/index.html#dbapp
1455214553
[153]: https://www.virtualbox.org
1455314554
[154]: http://www.oracle.com/technetwork/database/enterprise-edition/downloads/
14554-
[155]: https://docker.com/
14555+
[155]: https://github.com/oracle/docker-images
1455514556
[156]: http://yum.oracle.com/
1455614557
[157]: https://livesql.oracle.com/
1455714558
[158]: https://asktom.oracle.com/

0 commit comments

Comments
 (0)