Unable to connect to an Oracle 12c Docker container

dockerjdbcoracle

I'm working on a project with Oracle, and using a Oracle XE 11 container for testing. But recent developments have ended up with me running up against a brick wall: I need larger table names. Support for large table names was apparently added in version 12, so I'm trying to change out the container I'm using.

I'm setting up the container in Java using testcontainers:

db = new OracleContainer("epiclabs/docker-oracle-xe-11g");

When I look around on Docker Hub for Oracle 12 containers, I get a bunch of results, but every one I've tried so far, if I substitute its name in as the image name in the code above, it spins for 10-20 minutes, then errors out with

ORA-12514, TNS:Listener does not currently know of service requested in connect descriptor

And I have no idea what the problem is here. I have plenty of SQL experience, but next to none with Oracle specifically, and trying to get this Oracle-related project working has been a bit of a disaster so far. Does anyone know what's going wrong and how I can get connected to a Oracle 12 Docker container?

Best Answer

"Semi-official" images available on hub.docker.com

docker image ls
REPOSITORY         TAG           IMAGE ID       CREATED       SIZE
gvenzl/oracle-xe   18            e1d4dae1771b   4 days ago    3.69GB
gvenzl/oracle-xe   18.4.0        e1d4dae1771b   4 days ago    3.69GB
gvenzl/oracle-xe   latest        e1d4dae1771b   4 days ago    3.69GB
gvenzl/oracle-xe   18-full       13085168429b   12 days ago   6.36GB
gvenzl/oracle-xe   18.4.0-full   13085168429b   12 days ago   6.36GB
gvenzl/oracle-xe   full          13085168429b   12 days ago   6.36GB

docker-compose.yml for persistent database.

version: '3.8'
services:
  database:
    image: gvenzl/oracle-xe:18
    container_name: oracle
    environment:
      - ORACLE_PASSWORD=Welcome_1
    volumes:
      - type: volume
        source: oradata
        target: /opt/oracle/oradata
    ports:
      - 1521:1521
    networks:
      - dbnet
    healthcheck:
      test: sql -L -S sys/Welcome_1@localhost:1521/XEPDB1 as sysdba < /dev/null |grep 'ORA-'; if [[ $$? == 1 ]]; then echo 0; else echo 1; fi
      interval: 1m
      timeout: 10s
      retries: 20
      start_period: 40s
networks:
  dbnet:
volumes:
   oradata:
     driver: local
     driver_opts:
       type: none
       device: $PWD/oradata
       o: bind

Note, make sure "oradata" is rw by oracle user inside container.

Best of luck!