Sub topic 3
Running Oracle Database 26ai Free in a container
This chapter assumes you can run basic Docker or Podman commands (run, ps, logs, stop), that you know what a TCP port mapping is, and that you can read a short shell command. SQL beyond SELECT is not needed yet. The chapter covers starting the database, what happens during the first start, how to keep your data, and how to fix the usual startup problems. The next chapter covers connecting to the container database and FREEPDB1 in detail.
What the container gives you
Oracle publishes Oracle Database 26ai Free as a ready-made image in its own registry, container-registry.oracle.com. The image holds the database software, a listener (the process that accepts client connections on port 1521), and scripts that create a database the first time the container starts. You do not install anything on the host except a container runtime.
You get a full Oracle Database engine on your own machine. It has no network latency and no cloud account, and it keeps working offline once the image is pulled. The trade-off is that you manage it yourself. You decide where the data lives, you handle upgrades, and a wrongly removed container can take your tables with it.
Oracle Database Free has resource caps: a small number of CPU threads, about 2 GB of RAM for the instance, and about 12 GB of user data. Check the current release notes for the exact numbers for your version. The caps matter when you plan how much data to load, and the memory cap is the reason you should give the container at least a few gigabytes of RAM on Docker Desktop.
Starting the database
The simplest start uses one command. This is the command from the chapter plan:
docker run -d --name oracle-free \
-p 1521:1521 \
-e ORACLE_PWD='ChangeMe_123' \
container-registry.oracle.com/database/free:latestPodman accepts the same arguments, so you can replace docker with podman. The image name is fully qualified, which Podman needs because it does not assume a default registry.
| Part | What it does |
|---|---|
| `-d` | Runs the container in the background (detached). |
| `--name oracle-free` | Gives the container a stable name, so later commands do not need the generated ID. |
| `-p 1521:1521` | Maps host port 1521 to container port 1521, where the listener runs. |
| `-e ORACLE_PWD=...` | Sets the password for the `SYS`, `SYSTEM` and `PDBADMIN` accounts. |
| image name | `database/free` from Oracle's registry, with the tag `latest`. |
The first run pulls the image, which is several gigabytes, so the download can take a while. Oracle's Free image does not require you to sign in to the registry.
Choose the password deliberately
If you omit ORACLE_PWD, the image generates a random password and prints it to the container log. That works, but you must then find it in docker logs. Setting the password yourself is simpler for a practice setup. The value is stored in your shell history and visible in docker inspect, so do not reuse a password you use anywhere else.
Quote the value in single quotes. Characters such as $, ! and & are interpreted by the shell otherwise, and you would end up with a password different from the one you typed.
Pin the tag when repeatability matters
latest points to whichever release Oracle published most recently. Two machines that pulled at different times can end up with different versions. For a course, a team, or a bug reproduction, pick a specific tag from the registry's tag list and use it everywhere. Use latest only for personal experiments.
What happens during the first start
The database does not exist when the container first starts. The entrypoint script creates it, and that takes a few minutes depending on your CPU and disk. The container shows as "running" almost immediately, but the database is not ready to accept sessions until creation finishes.
Disregard the empty block above. The diagram follows in the correct form below.
Follow the log to see where you are:
docker logs -f oracle-free
# Wait for the line: DATABASE IS READY TO USE!Press Ctrl+C to stop following the log. This does not stop the container. If you try to connect before the "ready" line appears, you usually get a listener or service error such as ORA-12541 or ORA-12514. These are timing problems, not configuration problems. Wait and try again.
You can also use the container's health status:
docker ps --format 'table {{.Names}}\t{{.Status}}'The status reads (health: starting) during creation and (healthy) once the database is open. Scripts that wait for the database can poll this value instead of parsing the log.
Keeping your data: volumes
By default, the database files live inside the container's writable layer. They survive docker stop and docker start. They are lost when you run docker rm. For anything you want to keep, mount a volume at /opt/oracle/oradata, which is where the image stores the data files.
docker run -d --name oracle-free \
-p 1521:1521 \
-e ORACLE_PWD='ChangeMe_123' \
-v oracle-free-data:/opt/oracle/oradata \
container-registry.oracle.com/database/free:latestWith a named volume, as above, the runtime creates the volume and sets suitable ownership. You can remove and recreate the container, and the new container opens the existing database instead of creating a new one. The flow diagram shows this as the "Yes" branch.
A bind mount, which uses a host directory such as -v /home/me/oradata:/opt/oracle/oradata, is more fragile. The database runs as the oracle user inside the container, with user ID 54321. If the host directory is not writable by that ID, creation fails with permission errors in the log. On Linux you can fix this with chown 54321 on the directory. On systems with SELinux, add :Z to the mount so the label is set. Rootless Podman maps IDs differently again, so a named volume is the easier route.
The password only applies when the database is created
ORACLE_PWD is read when the database is created. If you restart a container on an existing volume with a different ORACLE_PWD, the stored password does not change. To change it, run the helper script that ships in the image:
docker exec oracle-free /home/oracle/setPassword.sh 'NewPassword_456'A compose file for repeatable setups
If you start the database often, a Compose file records the options in one place:
services:
oracle-free:
image: container-registry.oracle.com/database/free:latest
container_name: oracle-free
ports:
- "1521:1521"
environment:
ORACLE_PWD: ${ORACLE_PWD:?set ORACLE_PWD before starting}
volumes:
- oracle-free-data:/opt/oracle/oradata
volumes:
oracle-free-data:The ${ORACLE_PWD:?...} form makes Compose stop with an error if the variable is not set. Export it in your shell first (export ORACLE_PWD='ChangeMe_123') and then run docker compose up -d. This keeps the password out of the file, so you can commit the file to version control.
Optional startup settings and scripts
The image reads a few other environment variables on first creation:
ORACLE_CHARACTERSETsets the database character set. The default isAL32UTF8, which is the right choice unless you have a specific legacy need. You cannot change it casually after creation.ENABLE_ARCHIVELOG=trueturns on archive log mode, which you need to practice backup and recovery topics.ENABLE_FORCE_LOGGING=trueforces logging for all operations.
The image also runs SQL and shell scripts from two directories that you can mount:
| Directory in the container | When the scripts run |
|---|---|
| `/opt/oracle/scripts/setup` | After the database is created, only on the first start. |
| `/opt/oracle/scripts/startup` | After the database is opened, on every start. |
Scripts run in alphabetical order. Putting your user-creation SQL in setup means a fresh container comes up with your schema already in place. Because setup scripts run only when the database is created, a container that reuses an existing volume will not run them again.
Stopping, restarting and removing
docker stop oracle-freeasks the database to shut down. Docker waits ten seconds by default, then kills the process. A larger instance can need longer, so usedocker stop -t 60 oracle-freewhen you have been loading data. If the process is killed, the database performs crash recovery at the next start. That is safe but slows the start.docker start oracle-freerestarts the same container. It skips database creation and opens the existing files.docker rm oracle-freedeletes the container. Data in a named volume remains. Data in the container's own layer is gone.docker volume rm oracle-free-datadeletes the data permanently. Use it when you want a completely fresh database.
Quick check from inside the container
You do not need a client on the host to confirm the database is alive. SQL*Plus is in the image, so you can run it with docker exec:
docker exec -it oracle-free sqlplus sys/ChangeMe_123@localhost:1521/FREEPDB1 as sysdbaIf you get a SQL> prompt, the listener, the database and the pluggable database are all working. From a client on the host, the same Easy Connect string works against localhost:1521/FREEPDB1. The next chapter explains the difference between the container database and FREEPDB1.
Common startup problems
| Symptom | Likely cause | What to do |
|---|---|---|
| `port is already allocated` or `address already in use` | Another process, or another Oracle container, holds host port 1521. | Map a different host port, for example `-p 1522:1521`, and connect to port 1522. |
| `ORA-12541: no listener` or `ORA-12514` right after start | Creation is still running. | Follow `docker logs -f` until `DATABASE IS READY TO USE!` appears. |
| Container exits within seconds | Not enough memory, or permission errors on a bind mount. | Read `docker logs oracle-free`. Raise the memory limit in Docker Desktop, or switch to a named volume. |
| Login fails with `ORA-01017` | Wrong password, or the volume held an older database created with another `ORACLE_PWD`. | Use `setPassword.sh`, or remove the volume to recreate the database. |
| `pull access denied` or a name resolution error | Misspelled image name, or no network route to the registry. | Check the full name, and check any proxy settings for the runtime. |
| Very slow first start | Image pull or database creation on a slow disk or emulated CPU. | Wait, and if you are on an Arm machine check that you are using a native Arm image rather than emulation. |
When the symptom is unclear, the log is the first place to look. The creation steps are printed there, and so are the errors from any setup scripts.
Exercises
Exercise
You started a container without a volume, created a table and inserted rows. You then ran docker stop oracle-free followed by docker start oracle-free. Are the rows still there? What if you had run docker rm oracle-free instead of docker stop?
Show answer
After stop and start, the rows are still there, because the container's writable layer, which holds the data files, is kept and the database opens the existing files without recreating them. After docker rm, the container and its writable layer are deleted, so the rows are lost. To survive removal, mount a named volume at /opt/oracle/oradata.
Exercise
A colleague's container shows as running, but their SQL client reports ORA-12514 thirty seconds after docker run. Nothing is misconfigured. What is the explanation and how do they confirm it?
Show answer
The first start creates the database, which takes minutes, so the listener has no registered service yet. They can confirm it by running docker logs -f oracle-free and waiting for DATABASE IS READY TO USE!, or by checking that docker ps shows the status (healthy). Retrying after that point should succeed.
Exercise
You restart the container on an existing volume with a new ORACLE_PWD value, but you can only log in with the old password. Why, and how do you change the password without losing data?
Show answer
ORACLE_PWD is applied only when the database is created. An existing volume already holds the database, so the new value is ignored. Run docker exec oracle-free /home/oracle/setPassword.sh 'NewPassword_456' to change it in place.