Unable to connect to service on docker compose from dockerfile

Hi,
Why does my dockerfile keeps throwing the below error where i am simply doing a sqlplus command using the db service in the docker-compose so that it connects to the same container.
The same command works when on the container.
Any thoughts…

docker-compose:

`

version: '2.4'
services:
  db:
    image: oracle19c:new
    environment:
      - ORACLE_SID=ORCLCDB
      - ORACLE_PDB=ORCLPDB1
      - ORACLE_PWD=password
    ports:
      - 1521:1521
    volumes:
      #- oracle:/opt/oracle/oradata
      #- ./scripts:/scripts
      #- ./software:/software
      - ./scripts/:/opt/oracle/scripts/startup/
      - ./SQL-develop/:/tmp/SQL/
    healthcheck:
      test: [ "CMD", "/opt/oracle/checkDBStatus.sh"]
      interval: 10s
      timeout: 10s
      retries: 190


Please format your post according:

apologies for the formatting. This is now fixed

Thank you for making it more readable!

I’m not sure but using the CMD that way is usually not recommended. You can learn about the reasons here:

You should create a start script and run like this:

CMD ["/start.sh"]

The content of the start script could be:

#!/bin/sh
exec sqlplus sys/password123@db:1521/ORCLPDB1 as sysdba @/tmp/utPLSQL/source/install_headless.sql

Or I gues you would like to use environment variables instead of setting the password the way you tried in your quoted code.

Of course you don’t have to always create a start script, but it helps sometimes so you can have any shell you define in the first line if the command requires bash or anything else. And exec is important usually. In your case since the command runs and stops, it is not so important but doesn’t hurt.

Hello, thanks for your messge.
i created the start.sh and we still get the same error?

And how do you run it in a container when it works?

ive incorporated the execution of script in the docker-compose as appose to using a dockerfile. This way we can use depend_on to wait for the db build and then execute the script.

thanks for your messages. Appreciate it

If you mark your own post as solution, please also share the solution so other users can solve it too. “another way” itself is not a solution :slight_smile: Thank you!

1 Like