Running an Oracle Database (DB) Container on your laptop, regardless of your device, is a common practice for professionals in lab and engineering environments. These containers offer a convenient solution for setting up and managing Oracle databases for various purposes. However, there are scenarios where you need to interact with the Oracle DB Container using graphical user interfaces, such as Oracle Database Configuration Assistant (DBCA), Oracle Net Configuration Assistant (NETCA), and other X11-based tools.
In this quick tutorial, I will guide you through the process of running X11 applications from an Oracle DB Container, simplifying your database management tasks.
Quick Configuration Steps
In a rush? Ensure that the DISPLAY variable is correctly configured and allow ‘localhost’ to connect to your X11 server.
- To allow ‘localhost’ to connect to the X11 Server on your Docker host, run the following command:
xhost localhost
- Additionally, set the DISPLAY to
host.docker.internal:0
in your container. This resolves to the internal IP address used by the host:
export DISPLAY=host.docker.internal:0
For a deeper understanding and essential security considerations, keep reading.
Requirements
You have made it this far! 😎 In this case, you want a little more context. First, let’s take a look at what the requirements are for MacOS. For Linux or Windows based systems these have to be adapted accordingly.
- Docker Desktop You need Docker installed and running on your MacOS. If you don’t have it, you can download and install it from the official Docker website.
- XQuartz as X11 Server: XQuartz is an open-source X Window System server for macOS. You can install it from XQuartz’s official website.
- Oracle DB Container: You should have an Oracle DB Container up and running on your MacOS. If you haven’t set up the container yet, you have a couple of options:
- Get a prebuild Oracle image from Oracle Container Registry
- Build your own Oracle image using the scripts from oracle/docker-images
- Build your own Oracle image using the scripts from oehrlis/docker
And finally, the whole thing also works with any other container where you want to start an X11 application.
Configuration
Once you have the prerequisites in place, follow these steps to configure your environment for running X11 apps from your Oracle DB Container.
Add localhost to xhost
Before we start, open a terminal and add localhost
to the xhost access control list. This allows the Oracle DB Container to display graphical interfaces on your local XQuartz server.
xhost +localhost
Define the Environment Variable DISPLAY
You can define the DISPLAY environment variable in multiple ways: you can set it when running a docker exec
command, include it in your docker-compose
configuration, or configure it as an environment variable in an interactive session. The DISPLAY variable specifies the X11 server that the container should use for display.
Using docker exec
:
Run your Oracle DB Container and specify the DISPLAY environment variable:
docker exec -it -e DISPLAY=host.docker.internal:0 <container_name> <command>
Replace <container_name>
with the name of your Oracle DB Container and <command>
with the X11 application you want to run.
Using docker-compose
If you use docker-compose to manage your containers, you can add the DISPLAY environment variable to your docker-compose.yml file. Here’s an example:
services: oracle-db-container: environment: - DISPLAY=host.docker.internal:0
Make sure to replace oracle-db-container with the actual name of your Oracle DB Container.
What I left out – Additional Considerations
My configuration is indeed simple and straightforward. However, there are a few key points to consider for a more comprehensive setup:
- Network Configuration: The network configuration for my container is uncomplicated. It operates on the same network as the host system. If your setup requires the container to run on a separate network, you may need to use the
--net=host
flag to ensure it uses the host network. Be aware that changes to the xhost configuration may also be necessary in this scenario - X11 Configuration: In my setup, no xauth or .Xauthority file is employed. However, in some cases, you may need to share the .Xauthority file through a bind volume between the container and host for proper X11 authentication.
- Security Considerations: It’s important to acknowledge that enabling X11 access to your container also opens the door to potential security risks. The container can intercept access to the X server, including mouse and keyboard inputs, which may introduce security vulnerabilities such as key-logging. Therefore, it’s imperative to limit this approach to applications you trust to safeguard the security of your environment.
Conclusion
With these configurations in place, you’re now equipped to effortlessly run X11 applications from your Oracle DB or any other container. This capability empowers you to efficiently manage your Oracle databases with the convenience of graphical tools, further enhancing your lab and engineering environment on MacOS
Security Notice: Have I already mentioned it? It’s crucial to exercise caution when using this method. Only run applications you trust within the container because they gain access to X11, potentially allowing for activities like mouse and keyboard interception, such as key-logging. Therefore, limit this approach to trustworthy applications to ensure the security of your environment.
References
Some links related to this topic.
- X Window System server for macOS XQuartz’s official website
- Docker Desktop from the official Docker website
- Network Features on Docker Desktop
- Oracle DB Container:
- Get a prebuild Oracle image from Oracle Container Registry
- Build your own Oracle image using the scripts from oracle/docker-images
- Build your own Oracle image using the scripts from oehrlis/docker
- Running X11 applications like
xeyes
in Docker