oracle dockerfile没有正确使用docker compose服务

wkftcu5l  于 2023-10-16  发布在  Oracle
关注(0)|答案(1)|浏览(90)

为什么我的dockerfile一直抛出下面的错误,我只是在docker-compose中使用db服务执行sqlplus命令,以便它连接到同一个容器。同样的命令在容器上工作。有什么想法...
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/
      - ./utPLSQL-develop/utPLSQL-develop/:/tmp/utPLSQL/
    healthcheck:
      test: [ "CMD", "/opt/oracle/checkDBStatus.sh"]
      interval: 10s
      timeout: 10s
      retries: 190

  utplsql:
    build: ./
    depends_on:
      db:
        condition: service_healthy
    environment:
      - ORACLE_SID=ORCLCDB
      - ORACLE_PDB=ORCLPDB1
      - ORACLE_PWD=password

#######################################

dockerfile:

FROM oracle19c:new

# Setup ORACLE ENV
ENV ORACLE_SID=ORCLCDB
ENV ORACLE_PDB=ORCLPDB1
ENV ORACLE_PWD=password

# Set up the command to wait for the Oracle DB, then install utPLSQL
CMD sqlplus sys/password123@db:1521/ORCLPDB1 as sysdba @/tmp/utPLSQL/source/install_headless.sql

#########################################

构建时出错:

compose-utplsql-1  | 
compose-utplsql-1  | SQL*Plus: Release 19.0.0.0.0 - Production on Thu Oct 12 16:25:30 2023
compose-utplsql-1  | Version 19.3.0.0.0
compose-utplsql-1  | 
compose-utplsql-1  | Copyright (c) 1982, 2019, Oracle.  All rights reserved.
compose-utplsql-1  | 
compose-utplsql-1  | 
compose-utplsql-1  | ERROR:
compose-utplsql-1  | ORA-12504: TNS:listener was not given the SERVICE_NAME in CONNECT_DATA
compose-utplsql-1  | 
compose-utplsql-1  | 
compose-utplsql-1  | Enter user-name:
compose-utplsql-1 exited with code 0
goqiplq2

goqiplq21#

如果你想在创建数据库后灵活地运行脚本,可以使用gvenzl的images。这些都是很棒的,为开发人员!

cat > docker-compose.yml <<EOF
version: "3.9"

services:

  oracle:
    container_name: oracle-free
    image: gvenzl/oracle-free:latest
    environment:
      ORACLE_PASSWORD: Welcome_#1
      APP_USER: dev
      APP_USER_PASSWORD: dev
      TARGET_PDB: FREEPDB1
    ports:
      - 1521:1521
    volumes:
      - ./init_scripts:/container-entrypoint-initdb.d
    healthcheck:
      test: healthcheck.sh
      interval: 10s
      timeout: 5s
EOF

创建脚本文件夹并添加脚本

mkdir init_scripts

# utilize the new 23c dev role 'db_developer_role'

cat > init_scripts/01_grant_db_developer_role.sql <<EOF
alter session set container=freepdb1;
grant db_developer_role to dev;
EOF

Oracle数据库启动例程配置为吃掉此文件夹中的所有脚本

tree init_scripts/
init_scripts/
└── 01_grant_db_developer_role.sql

1 directory, 1 file

启动数据库服务

docker compose up -d

以app用户'dev'登录

export TWO_TASK=localhost/FREEPDB1
sqlplus dev/dev

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Oct 13 07:15:00 2023
Version 19.8.0.0.0

Copyright (c) 1982, 2020, Oracle.  All rights reserved.

Last Successful login time: Fri Oct 13 2023 07:12:18 +02:00

Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0

dev@FREEPDB1>

我被分配到新的23 c角色了吗?

dev@FREEPDB1> select granted_role, admin_option, default_role
  2  from
  3    user_role_privs
  4  order by granted_role;

GRANTED_ROLE         ADM DEF
-------------------- --- ---
CONNECT              NO  YES
DB_DEVELOPER_ROLE    NO  YES
RESOURCE             NO  YES

3 rows selected.

从这里,您可以将整个互联网加载到Oracle数据库中。
祝你好运!

相关问题