使用docker启动Oracle Database 23c免费开发者版本
以前,为了在开发和验证环境中启动Oracle,使用Docker需要进行一些镜像构建等繁琐的步骤,但现在通过使用https://container-registry.oracle.com/ords/ocr/ba/database/free提供的镜像,变得非常简单。
例如,只是试一下的话,以下的方法就足够了。尽管首次执行 Docker pull 需要相当一段时间。
docker run --name myoracle -p 11521:1521 -e ORACLE_PWD="a" container-registry.oracle.com/database/free:23.2.0.0
以下是用于启动确认的Spring应用程序。
plugins {
id 'java'
id 'org.springframework.boot' version '3.1.5'
id 'io.spring.dependency-management' version '1.1.3'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
java {
sourceCompatibility = '17'
}
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
runtimeOnly 'com.oracle.database.jdbc:ojdbc8'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
spring.datasource.url jdbc:oracle:thin:@localhost:11521/FREEPDB1
spring.datasource.username system
spring.datasource.password a
@SpringBootApplication
public class OracleSampleMain implements ApplicationRunner {
public static void main(String[] args) {
SpringApplication.run(OracleSampleMain.class, args);
}
@Autowired
DataSource ds;
@Override
public void run(ApplicationArguments args) throws Exception {
JdbcTemplate t = new JdbcTemplate(ds);
System.out.println(t.queryForObject("select 1 from dual", Integer.class));;
}
}
运行Docker时的启动日志供参考。
Starting Oracle Net Listener.
Oracle Net Listener started.
Starting Oracle Database instance FREE.
Oracle Database instance FREE started.
The Oracle base remains unchanged with value /opt/oracle
SQL*Plus: Release 23.0.0.0.0 - Developer-Release on Sun Nov 5 10:11:44 2023
Version 23.2.0.0.0
Copyright (c) 1982, 2023, Oracle. All rights reserved.
Connected to:
Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0
SQL>
User altered.
SQL>
User altered.
SQL>
Session altered.
SQL>
User altered.
SQL> Disconnected from Oracle Database 23c Free, Release 23.0.0.0.0 - Developer-Release
Version 23.2.0.0.0
The Oracle base remains unchanged with value /opt/oracle
#########################
DATABASE IS READY TO USE!
#########################
The following output is now a tail of the alert.log:
FREEPDB1(3):Autotune of undo retention is turned on.
FREEPDB1(3):Undo initialization recovery: Parallel FPTR failed: start:1651134 end:1651136 diff:2 ms (0.0 seconds)
FREEPDB1(3):[163] Successfully onlined Undo Tablespace 2.
FREEPDB1(3):SUPLOG: Set PDB SUPLOG SGA at PDB OPEN, old 0x18, new 0x0 (no suplog)
FREEPDB1(3):Opening pdb with Resource Manager plan: DEFAULT_PLAN
2023-11-05T10:11:44.072875+00:00
Completed: Pluggable database FREEPDB1 opened read write
Completed: ALTER DATABASE OPEN
2023-11-05T10:11:44.498176+00:00
FREEPDB1(3):TABLE AUDSYS.AUD$UNIFIED: ADDED INTERVAL PARTITION SYS_P371 (3415) VALUES LESS THAN (TIMESTAMP' 2023-11-06 00:00:00')