You need to enable JavaScript to run this app.
最新活动
大模型
产品
解决方案
定价
生态与合作
支持与服务
开发者
了解我们

Docker Oracle容器中sqlplus命令未找到问题求助(Docker新手)

Fixing "sh: sqlplus: command not found" in Your Oracle Docker Build

Hey there! Let's walk through the issues in your Dockerfile that's causing the sqlplus: command not found error, and get your Oracle container working properly.

Key Issues Identified

  • FROM directive isn't the first instruction: In Docker, the FROM command must be the first non-comment line in your Dockerfile. Any instructions before FROM (like your initial ENV and RUN commands) get discarded because FROM resets the entire build context.
  • Incorrect ORACLE_HOME path: You've set ORACLE_HOME to the full path of the sqlplus binary, but this environment variable should point to the root directory of your Oracle installation, not the executable itself. The correct path is /u01/app/oracle/product/12.2.0/dbhome_1sqlplus lives inside the bin subdirectory of this path.
  • Missing leading slashes in paths: Lines like echo 'export ORACLE_HOME=u01/app/oracle/product/12.2.0/dbhome_1/bin/sqlplus' >> etc/bash.bashrc are missing leading / for both the ORACLE_HOME value and the bash.bashrc path, making them relative instead of absolute (so the system can't find them).
  • Running database initialization scripts during build: Oracle databases need to be initialized when the container starts (not during the build phase), because the Oracle service isn't running while building the image. Running these scripts in RUN commands will fail because sqlplus can't connect to a non-existent database instance.

Corrected Dockerfile

# Start with the base Oracle image (must be the first instruction)
FROM registry-innersource.soprasteria.com/sib/docker/db-oracle-12.2.0.1

# Switch to root user for setup tasks
USER root

# Set correct Oracle environment variables
ENV ORACLE_HOME=/u01/app/oracle/product/12.2.0/dbhome_1
ENV PATH=$ORACLE_HOME/bin:$PATH

# Set other required environment variables
ENV SYS_USER SYS
ENV SYS_PASSW password
ENV JAVA_HOME /u01/java/jdk1.8.0_201

# Copy your files into the image
COPY DB_SIB_SET_OS_COMMON_VARIABLES.sh /u01/oracle/
COPY 2_create_tablespaces.sh /u01/oracle/
COPY 3_setup_SIB.sh /u01/oracle/
COPY apache-jmeter-5.0 /u01/jmeter/
COPY JmeterScenario /u01/jmeter/JmeterScenario
COPY jdk-8u201-linux-x64.tar.gz /u01/java/
COPY Environment /Environment
COPY _util /_util

# Set permissions and extract JDK
RUN chmod a+xr /u01/java/ && \
    chmod 777 /_util && \
    tar xzf /u01/java/jdk-8u201-linux-x64.tar.gz

# Move initialization scripts to a startup directory (check base image docs for exact path)
# Most Oracle base images auto-run scripts in /docker-entrypoint-initdb.d/ when the container starts
RUN mv /u01/oracle/*.sh /docker-entrypoint-initdb.d/ && \
    chmod a+x /docker-entrypoint-initdb.d/*.sh

# Switch back to oracle user if required by the base image
USER oracle

Additional Notes

  1. Verify the base image's entrypoint: Check the documentation for registry-innersource.soprasteria.com/sib/docker/db-oracle-12.2.0.1 to confirm the correct directory for initialization scripts. Many Oracle Docker images automatically run .sh or .sql files in a designated folder when the container starts (after the database is fully up).
  2. Test sqlplus access: Once you've built the corrected image, run a temporary container to verify sqlplus works:
    docker run -it --rm your-built-image-name sqlplus /nolog
    
  3. Clean up redundant commands: I removed duplicate chmod and USER root commands from your original Dockerfile to streamline the build process.

内容的提问来源于stack exchange,提问作者taveced

火山引擎 最新活动