【发布时间】:2016-11-05 14:41:38
【问题描述】:
我正在使用 wnameless/oracle-xe-11g docker 镜像来创建一个新的镜像文件。当我从新图像创建容器时,我希望执行 impdp 命令。这如何通过 Dockerfile 实现?
这是我的 Docker 文件
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.
现在我通过 ssh 进入容器并运行 impdp 手动执行此操作。我尝试使用
CMD ["impdp", "system/oracle NOLOGFILE=Y DIRECTORY.."]
但不起作用并引发异常。
所以我的问题是“这可能吗”?如果可以,请提供如何实现的代码示例?
谢谢,
更新:例外不是在创建图像时而是在尝试从中创建容器时。
例如,如果我将此作为我的 docker 文件的最后一行
CMD [“impdp”, “system/oracle NOLOGFILE=Y DIRECTORY=expdp_dir
DUMPFILE=SAMPLE_MASTER.EXPDP SCHEMAS=c##sample transform=OID:n”]
然后做一个
docker build -t my/my_oracle .
然后运行它
docker run -d -p 49160:22 -p 49161:1521 my/my_oracle
并检查
docker logs <container_id>
我明白了
/bin/sh: 1: ["impdp", : not found
【问题讨论】:
-
您可能应该在问题中包含异常。
-
每个 docker 文件只能有一个 CMD 或入口点,但除了任何例外情况外,它应该可以工作。
-
嗨@ChristianWattengård 添加了异常/错误。
-
@Trying-to-learn 可以尝试使用
docker exec -i -t <image_id> /bin/bash附加到容器中,从/中找到 impdp 数据泵二进制文件的位置,例如find . -name "impdp" /然后尝试在 CMD [] 区域中指定 impdp 的完整路径,而不仅仅是"impdp" -
@Trying-to-learn 忘了提及。让我知道这是否有效,谢谢。
标签: docker oracle11g dockerfile impdp