Oracle Container Keeps Restarting: How to Handle with Docker Compose

Abstract: Resolve Oracle container restart loops by adjusting memory limits and configuring health checks in docker-compose to accommodate slow initialization.

Created: 2026-09-29 by

Oracle containers using the gvenzl/oracle-xe:21-slim image restart repeatedly because they require significant time to initialize database structures and listeners. This behavior is often mistaken for a crash, but it is actually a standard startup phase that Docker interprets as a failure due to aggressive health checks or insufficient memory allocation. By adjusting resource limits and configuring appropriate wait strategies in your docker-compose.yml file, you can stabilize the container and prevent unnecessary restart loops.

Understanding the Restart Loop Mechanism

When you run an Oracle Express Edition (XE) container, the application does not start instantly. The database must perform several critical tasks before it becomes available to accept connections. These tasks include initializing the data dictionary, creating system tablespaces, setting up default users, and starting the listener process. In a constrained environment, these operations can take several minutes. Docker monitors the container's health status. If the container does not respond to health checks within a specific timeframe, Docker considers the container unhealthy. Depending on your configuration, Docker may then attempt to restart the container automatically. If the initialization process is still ongoing when the restart occurs, the new instance begins from scratch, leading to an infinite restart loop. This is particularly common with lightweight images like gvenzl/oracle-xe:21-slim, which are optimized for size but may have less overhead tolerance than full enterprise editions. The core issue is rarely a bug in the Oracle software itself. Instead, it is a mismatch between the container's initialization requirements and Docker's expectations for rapid availability. To resolve this, we must align Docker's monitoring settings with the actual time required for Oracle to become ready.

Memory Constraints and Swap Issues

Another frequent cause of restarts is insufficient memory. Oracle XE has strict memory requirements. If the host machine does not provide enough RAM, or if Docker is allocated too little memory, the Oracle process may be killed by the operating system's Out-Of-Memory (OOM) killer. When the process dies unexpectedly, Docker sees this as a crash and restarts the container. You should verify that your Docker daemon is configured with adequate memory resources, typically at least 2GB to 4GB for stable operation, depending on your workload.

Configuring Docker Compose for Stability

The most effective way to handle this issue is through proper configuration in your docker-compose.yml file. We need to address two main areas: restart policies and health checks. A robust configuration ensures that Docker waits for the database to be truly ready before considering the service active. First, let us look at the restart policy. The default restart policy might be set to always or unless-stopped. While these seem helpful, they can exacerbate the problem if the container is stuck in a initialization-restart cycle. A more controlled approach involves using a retry limit or disabling automatic restarts during development so you can inspect logs. However, for production stability, we want the container to stay up once it is healthy. Here is a recommended structure for your docker-compose.yml:
version: '3.8'
services:
  oracle-db:
    image: gvenzl/oracle-xe:21-slim
    environment:
      - ORACLE_PASSWORD=YourStrongPassword123
      - ORACLE_CHARACTERSET=AL32UTF8
    ports:
      - "1521:1521"
    volumes:
      - oracle_data:/opt/oracle/oradata
    deploy:
      resources:
        limits:
          memory: 4G
    healthcheck:
      test: ["CMD", "sqlplus", "-L", "sys/YourStrongPassword123@localhost/XEPDB1 as sysdba", "select 'UP' from dual;"]
      interval: 30s
      timeout: 10s
      retries: 15
      start_period: 60s
volumes:
  oracle_data:
In this configuration, we explicitly set the memory limit to 4GB to prevent OOM kills. The healthcheck section is crucial. It uses sqlplus to verify that the database is accepting connections. The start_period is set to 60 seconds, giving the container ample time to initialize before Docker starts checking its health. The retries value allows for multiple failed checks before marking the service as unhealthy.

Adjusting Health Check Intervals

If you find that even 60 seconds is not enough for your specific hardware, you can increase the start_period. This parameter tells Docker to ignore health check failures during the initial startup phase. For example, setting it to 120 seconds provides a longer buffer. Additionally, increasing the interval between checks reduces the load on the container during the sensitive initialization window. This approach is far more reliable than trying to guess exact timeouts via environment variables, which are not supported by all Oracle images. For those interested in broader orchestration techniques, understanding how to manage multiple services is key. You might also find value in reading How to Orchestrate Three Containers with Docker-Compose to see how dependency management works in complex setups.

Diagnosing Persistent Failures

If the container continues to restart despite these configurations, you need to investigate deeper. Use the docker logs command to view the output of the Oracle container. Look for errors related to memory allocation, disk space, or permission issues. Common error messages include "ORA-00600" internal errors or "Listener refused the connection," which indicate that the listener is not yet ready. You can also use docker inspect to check the exit code of the container. An exit code of 137 usually indicates an OOM kill, confirming that memory was the bottleneck. If the exit code is different, refer to the Oracle documentation for that specific error code. In many cases, simply ensuring that the host machine has sufficient free RAM and swap space resolves the issue. It is also worth noting that network connectivity within the Docker network can sometimes cause issues. If other services depend on this Oracle container, ensure they are configured to wait for the health check to pass. This prevents connection errors that might trigger cascading failures. For insights into managing such dependencies, consider reviewing Microservice Health Check Instance Docker, which discusses best practices for service readiness.

Best Practices for Long-Term Stability

To maintain a stable Oracle container environment, follow these guidelines:
  • Monitor Resource Usage: Regularly check the memory and CPU usage of the container. Ensure it stays within the allocated limits.
  • Use Persistent Volumes: Always mount a volume for /opt/oracle/oradata. This prevents data loss during restarts and speeds up subsequent startups.
  • Avoid Over-Optimization: Do not reduce memory limits below 2GB unless you are certain about your workload. Oracle XE is resource-intensive.
  • Update Images Regularly: Pull the latest version of the gvenzl/oracle-xe image to benefit from bug fixes and performance improvements.
By implementing these configurations and monitoring practices, you can eliminate the frustrating restart loops and ensure your Oracle database remains available and stable.

Frequently Asked Questions

Why does my Oracle container restart immediately after starting?

This usually happens because Docker's health check fails before the database is fully initialized. The container needs time to create tablespaces and start the listener. Increasing the start_period in your health check configuration gives the database the necessary time to become ready without triggering a restart.

Can I disable the health check entirely to stop restarts?

You can disable the health check by removing the healthcheck block from your docker-compose.yml. However, this is not recommended for production environments because Docker will not know if the database is actually functional. It is better to configure the health check correctly rather than disabling it.

What is the minimum memory required for gvenzl/oracle-xe?

While Oracle XE can technically run with less, it is strongly recommended to allocate at least 2GB of RAM. For smooth operation and to avoid OOM kills, 4GB is the ideal target. Insufficient memory causes the Oracle process to crash, leading to immediate restarts by Docker.

How do I check if the database is actually running inside the container?

You can execute commands inside the running container using docker exec -it <container_name> bash. Once inside, run ps aux | grep pmon to see if the Oracle background processes are active. You can also try connecting with sqlplus to verify accessibility.

Does switching to the official Oracle image fix the restart issue?

The official Oracle images are heavier and may behave differently, but they still require initialization time. The restart issue is primarily caused by Docker's timing assumptions, not the image itself. Properly configuring health checks and resource limits is the correct solution regardless of the image used.

Latest News

How to Display Output of xterm Command in Terminal Screen using Cron

Resolve the inability to display xterm output in a terminal screen from cron by redirecting logs or using wall instead of insecure X11 workarounds.

Read More
Expose Local Server on VPS Preserving Real Client IPs (OS Level)

Resolve VPS logging showing only gateway IPs by configuring reverse proxies to forward real client addresses via X-Forwarded-For headers.

Read More
How to Clear Recent Files History in Linux without Deleting Actual Files?

Clear recent files history in Linux by deleting ~/.local/share/recently-used.xbel without removing the actual files.

Read More
Best HDD Copy Strategy: Manually Syncing and Rewriting Scratch

Resolve data drift between two 4TB hard drives by using rsync with the --delete flag to manually sync and rewrite scratch data for an exact mirror.

Read More
Understanding Bash Prompt Abbreviations: An Overview

Resolve repetitive typing errors by creating and persisting Bash aliases in the .bashrc file for improved command-line efficiency.

Read More
Free Tools and Methods to Log Real-Time Performance Details in Task Manager

Log real-time CPU and memory metrics to CSV files using Windows Performance Monitor Data Collector Sets to troubleshoot system slowness.

Read More
Contact Qatar Airways Customer Service: Phone Number, Help Center, and More

Resolve urgent Qatar Airways reservation issues like flight changes and baggage claims using the US phone number +1801-855-5905 or online self-service tools.

Read More
Windows 11: Alt Codes Displaying Wrong Characters - Solutions

Resolve Windows 11 Alt codes showing wrong characters by verifying the US keyboard layout and enabling Num Lock.

Read More
Run Programs with Elevated Privileges: A Comprehensive Guide

Eliminates the need to type sudo for frequent administrative tasks by configuring .bashrc aliases or functions.

Read More
Dynamically Changing Dates in Excel Formulas Using Cells

Eliminate manual date updates in Excel by using cell references to create dynamic formulas that automatically adjust calculations when input dates change.

Read More
Granting Edit Access to a Specific Excel Sheet in an Office 365 User Email ID-Based Login

Excel Online lacks native sheet-level permissions, so users must split workbooks or use worksheet protection to isolate edit access for specific tabs.

Read More
Creating Network Load on Local Wi-Fi from One PC

Generate sustained Wi-Fi bandwidth load from a single PC using a VM SFTP server to test router stability and throughput.

Read More
Changing the Default Editor for Batch Files in Windows 11's File Explorer

Resolve the issue of batch files opening in Notepad by changing the default editor to a preferred application like VS Code.

Read More
Gain WiFi Connection Minutes Before Losing it by Changing MAC Address

Bypass MAC address filtering to restore WiFi connectivity temporarily when a device is blocked by network administrators.

Read More
Photos Folders Turned Black: Troubleshooting Picture Applications on Windows

Resolve black screens in Windows Photos by resetting the app, updating graphics drivers, and repairing system files.

Read More
Troubleshooting High CPU Temperature Values: A Step-by-Step Guide

Resolve high CPU temperatures and thermal throttling by monitoring with Speedfan, cleaning dust from cooling components, and replacing degraded thermal paste.

Read More
Make cURL establish TLS connection with CA unknown

Resolve cURL TLS connection failures with unknown or self-signed certificates by using the --insecure flag to bypass CA validation.

Read More
Troubleshooting Incorrect Network Metrics Values in Grafana, Prometheus, InfluxDB, and Telegraf

Fix incorrect network metrics in Grafana, Prometheus, InfluxDB, and Telegraf by verifying interface selection, resolving unit mismatches, and handling counter resets.

Read More
Start Another Terminal Window (cmd.exe) Windows Repair/Troubleshoot

Provides step-by-step instructions to access the Windows Command Prompt via bootable media for advanced system repair and troubleshooting.

Read More
Thinkpad P1 Gen 6: Sudden Thunderbolt 3 Dock USB-C Charging Stopped Working

Resolve sudden Thunderbolt 3 dock USB-C charging and internet failure on ThinkPad P1 Gen 6 by updating firmware, resetting the dock, and adjusting power settings.

Read More
ASUS Windows 11 Laptop: Internet Connection Issue with Hotspot

Resolve ASUS Windows 11 laptop spinning wheel issue when connecting to mobile hotspot by resetting network stack, disabling IPv6, and adjusting power settings.

Read More
Developing iOS Project with Firebase: Logging in and Sending Push Notifications

Integrates Firebase to enable secure user authentication and push notifications in iOS applications.

Read More
Troubleshooting Bash Script with Suspected Issues of Spaces, Dashes, Filenames and Quoting

Resolve Bash script failures caused by word splitting, globbing, and special characters in filenames by applying proper quoting techniques.

Read More
Populating OneDrive Folder for Local Backup without Affecting Remote Files

Prevent OneDrive from deleting remote files during Windows reinstallation by unlinking the account or using symbolic links to isolate local data.

Read More
Force First Frame as Keyframe Without Re-encoding: A Quick Solution

Resolve inaccurate seeking and playback glitches by re-encoding video to ensure the first frame is a valid keyframe.

Read More
Find Information in Database Using WSL (Ubuntu) on Windows-10

Resolve database connection issues from WSL Ubuntu on Windows 10 by configuring client tools and network access to query remote or local servers.

Read More
Configuring a New Router with Different Networks: One Family, One Guest

Resolve IP conflicts and isolate guest traffic by configuring a second router with a distinct subnet via its WAN port.

Read More
Quickly Open Multiple Stock Websites with a Single Command

Solve the problem of manually opening multiple stock research websites by creating a single command to launch them simultaneously on Windows, macOS, or Linux.

Read More
Improved Adobe Acrobat Search Experience: Access Advanced Search with Ease

Access advanced search filters like case sensitivity and regex in Adobe Acrobat by clicking More Options in the Find bar.

Read More
Port Forwarding VM via OpenVPN: A Comprehensive Guide

Configure OpenVPN server and iptables to forward specific ports from VPN clients to a virtual machine's internal IP address.

Read More
Understanding Partitions in the 1980s: A Look Back at MS-DOS and Master Boot Record

Explains how the Master Boot Record and partition table enabled MS-DOS to manage multiple disk volumes on a single physical drive.

Read More
Windows 10 Enterprise: Keyboard Not Detected in Managed Organization with Admin Privileges

Resolve Windows 10 Enterprise keyboard detection failures caused by Group Policy restrictions, driver corruption, or USB enumeration errors.

Read More
Can't Find x86_64 Versions of Applications on MacOS arm64 (M1)

Resolve missing x86_64 app issues on M1 Macs by installing Rosetta 2 and reinstalling apps as universal binaries.

Read More
How to Hide Installation Source for an Android App

Manage Android app installation source visibility by using USB transfers or file managers to reduce browser traces and isolate data via work profiles.

Read More
Connecting Momentus 4200.2 ST9808210A Hard Drive via USB Cable

Resolve inability to access Seagate Momentus 4200.2 ST9808210A hard drive by connecting it via USB using a compatible SATA-to-USB adapter and configuring the disk in Windows.

Read More