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
FROMdirective isn't the first instruction: In Docker, theFROMcommand must be the first non-comment line in your Dockerfile. Any instructions beforeFROM(like your initialENVandRUNcommands) get discarded becauseFROMresets the entire build context.- Incorrect
ORACLE_HOMEpath: You've setORACLE_HOMEto the full path of thesqlplusbinary, 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_1—sqlpluslives inside thebinsubdirectory 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.bashrcare missing leading/for both theORACLE_HOMEvalue and thebash.bashrcpath, 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
RUNcommands will fail becausesqlpluscan'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
- Verify the base image's entrypoint: Check the documentation for
registry-innersource.soprasteria.com/sib/docker/db-oracle-12.2.0.1to confirm the correct directory for initialization scripts. Many Oracle Docker images automatically run.shor.sqlfiles in a designated folder when the container starts (after the database is fully up). - Test
sqlplusaccess: Once you've built the corrected image, run a temporary container to verifysqlplusworks:docker run -it --rm your-built-image-name sqlplus /nolog - Clean up redundant commands: I removed duplicate
chmodandUSER rootcommands from your original Dockerfile to streamline the build process.
内容的提问来源于stack exchange,提问作者taveced




