Today I needed some tools to manage the oracle database in a Ubuntu dockerimage. I need to use “imp” and “exp” to restore some tables in Oracle, therefore I’ve build this image.
Regarding to the docs from Oracle : Instant Client for Linux x86–64 (64-bit) (oracle.com) — I found this solution:
FROM ubuntu:22.04
ENV LD_LIBRARY_PATH=/opt/oracle/instantclient_19_24:$LD_LIBRARY_PATH
ENV PATH=/opt/oracle/instantclient_19_24:$PATH
RUN apt update -y && \
apt upgrade -y && \
apt install -y curl \
libaio1 \
unzip
RUN mkdir -p /opt/oracle
WORKDIR /opt/oracle
RUN curl -o oracleclient.zip https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-basic-linux.x64-19.24.0.0.0dbru.zip && \
curl -o sqlplus.zip https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-sqlplus-linux.x64-19.24.0.0.0dbru.zip && \
curl -o oracletools.zip https://download.oracle.com/otn_software/linux/instantclient/1924000/instantclient-tools-linux.x64-19.24.0.0.0dbru.zip && \
unzip oracleclient.zip && \
unzip oracletools.zip && \
unzip sqlplus.zip && \
sh -c "echo /opt/oracle/instantclient_19_24 > \
/etc/ld.so.conf.d/oracle-instantclient.conf" && \
ldconfig
Now I can run this with docker compose and mount my tnsnames.ora
version: '3'
services:
oracleclient:
build:
context: .
dockerfile: Dockerfile_TestAgent
volumes:
- ./tns:/etc/oracle
- ./exportedData:/exportedData
env_file:
- .env
entrypoint: ["/bin/sh","-c","exp $USER/$PASSWORD@$DATABASE file=/exportedData/dump.dmp log=/exportedData/dump.log tables=PROVIDER_FUNKCUSTOMUSERS,IDENTITY_OAUTH_APPLICATION"]
The related .env file is
TNS_ADMIN=/etc/oracle
USER=ORACLEUSER
PASSWORD=SOMEPASSWORD
DATABASE=TNSNAME