Hi everyone,
Now I want to configure docker file to run imdp command when container is created. This is my docker file based on a source from web by someone that I try to create. Anyone can help me to complete it. Thank you in advance.
# Base Image
FROM absolutapps/oracle-12c-ee:latest
# Create oracle_dump folder at / -location
RUN mkdir /var/lib/sharedata;
# Give permission
RUN chmod 777 '/var/lib/sharedata';
#VOLUME
MOUNT /home/huynn/Downloads/share:/var/lib/sharedata
# Give permission to user oracle on oracle folder to create tablespace
and related operations
RUN chown -R oracle /u01/app/oracle/oradata/orcl
# Alter datafiles
Alter tablespace USERS add datafile '/u01/app/oracle/oradata/orcl/users02.dbf' size 30G autoextend on;
Alter tablespace USERS add datafile '/u01/app/oracle/oradata/orcl/users03.dbf' size 30G autoextend on;
# 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.
CMD /usr/sbin/startup.sh
&& bin/bash -c "/u01/app/oracle/product/12.1.0.2/dbhome_1/bin/impdp
sys/oracle schemas = test DIRECTORY=ORACLE_DUMP DUMPFILE= mydumpfile exclude=index,constraint,statistics,grant PARALLEL=4 nologfle=y
"
&& /usr/sbin/sshd -D
# Add env variables for oracle_home and related
ENV ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin \
ORACLE_SID=xe
#Export oracle_home and related
RUN echo 'export ORACLE_HOME=/u01/app/oracle/product/12.1.0.2/dbhome_1/bin' >> etc/bash.bashrc
RUN echo 'export PATH=$ORACLE_HOME/bin:$PATH' >> /etc/bash.bashrc
RUN echo 'export ORACLE_SID=xe' >> /etc/bash.bashrc
P/s: because I am new one to docker, so I am very happy if you can describe detail about the solution.
A Dockerfile is the blueprint that instructions how to build an image. Thus said, I have no idea how to “complete” this Dockerfile as it makes no sense to way it is now.
May I suggest to re-read the dockerhub description of the base image? It specificly mentions how to execute arbitrary shell or sql script during contaienr start. Please validate wether it is an option to archive what you want.
thanks @meyay for your link. I have been watching it, it is a long book. I have been read it to enhance my knowledge about docker. Now I need to save time to handle my issues.
I understand, but I need you to read chapter 2 which explains how images work. With the new understanding, I like you to create a new post about what you want, this time with every part where it belongs - most of your Dockerfile content looks like it doesn’t belong here.
Reading chapter 2 will help you to understand wether its a good idea to make the database creation part of the image or part of the image’s entrypoint script - which is used by a container on every start.
If all of this is too much, I would suggest to NOT create your own image, but instead follow instructions from the section " Running scripts at startup" from the dockerhub description of the absolutapps/oracle-12c-ee.
N.B the image was created 6 years ago and is not patched since. So be prepared that it has a lot of vulnerabile in the os level packages and the installed database itself.
Maybe I quite understand, so now I will try to two ways you suggested.
Now I want to configure dockerfile of absolutapps by add shell sciprts into entrypoint.sh or add CMD imdp command in dockerfile. I build that docker file to a new image.
When I run with a new name image it shows me the permission about exec entrypoint.sh .
I add RUN chmod +x entrypoint.sh in my dockerfile. It helps me to solve that permission but now it shows when I run
docker exec -i -t oracle sqlplus sys/****@localhost:1521/ORCL as SYSDBA
Error response from daemon: Container a94fefcedf14dfb1cb55166653ff950c9523317d58a4c8ed6d194d4c0178cf5b is not running
Please start with the approach the image maintainer intended and documented in the dockerhub description. It would strongly advise to start with what you can master.