'Configure Dockerfile to use impdp command when the container is created
I am using wnameless/oracle-xe-11g docker image to create a new image file. And when I create a container from the new image I want the impdp command to be executed. How can this be achieved via Dockerfile?
Here is my Docker file
Dockerfile
# Base Image
FROM wnameless/oracle-xe-11g
# Create database_dump folder at / -location
RUN mkdir ../database_dumps
# Copy the dump file and put it into database_dumps created earlier
COPY dump_file ../database_dumps
# Give permission to user oracle on oracle folder to create tablespace
and related operations
RUN chown -R oracle /u01/app/oracle/oradata/XE
# RUN the database initial sql.(create tablespace, create user etc)
ADD init.sql /docker-entrypoint-initdb.d/
# Here is where I want to call the impdp command. when a container is
created from this image.
For now I am doing this manually by ssh-ing into the container and running the impdp. I tried to do it using the
CMD ["impdp", "system/oracle NOLOGFILE=Y DIRECTORY.."]
but does not work and throws exception.
So my question is "Is this possible"? If yes can you please provide the code example of how this can be achieved?
Thanks,
Update: The exception is not when creating the image but when trying to create a container from it.
So for example If I include this as the last line of my docker file
CMD [“impdp”, “system/oracle NOLOGFILE=Y DIRECTORY=expdp_dir
DUMPFILE=SAMPLE_MASTER.EXPDP SCHEMAS=c##sample transform=OID:n”]
Then do a
docker build -t my/my_oracle .
and run it as
docker run -d -p 49160:22 -p 49161:1521 my/my_oracle
and check for
docker logs <container_id>
I see that
/bin/sh: 1: ["impdp", : not found
Solution 1:[1]
Create a simple shell script ur_script.sh which will run the impdp command.
#!/bin/bash
echo Load DDL and DML
export TIMESTAMP=`date +%a%d%b%Y`
$ORACLE_HOME/bin/impdp system/oracle full=Y directory=data_pump_dir dumpfile=sample_data.dmp logfile=expdp_log_${TIMESTAMP}.log
echo Complete
Add this shell script to /docker-entrypoint-initdb.d/ as instructed in the original image https://hub.docker.com/r/wnameless/oracle-xe-11g-r2
# Dockerfile
FROM wnameless/oracle-xe-11g-r2
ADD ur_script.sh /docker-entrypoint-initdb.d/
This script will be automatically executed when the container started for first time. And your db dump will be loaded
Solution 2:[2]
I think you're getting messed up by the "smart" quotes here:
CMD [“impdp”, “system/oracle NOLOGFILE=Y DIRECTORY=expdp_dir DUMPFILE=SAMPLE_MASTER.EXPDP SCHEMAS=c##sample transform=OID:n”]
Change that to (I've also separated each cli parameter):
CMD ["impdp", "system/oracle", "NOLOGFILE=Y", "DIRECTORY=expdp_dir", "DUMPFILE=SAMPLE_MASTER.EXPDP", "SCHEMAS=c##sample", "transform=OID:n"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Vrishank |
| Solution 2 |
