Ensure Docker is installed and running on your laptop.
Open a terminal and pull the CentOS 9 Docker image: docker pull centos:9
Create and start a CentOS 9 container: docker run -it --name my-centos9 centos:9
Inside the CentOS container, install Java 18. You can either download the JDK manually or use tools like yum or dnf if they're available in the CentOS 9 repository.
Similarly, install Tomcat within the container. Download the Tomcat package and configure it according to your requirements.
Still within the container, install PostgreSQL: yum install postgresql-server postgresql-contrib
Initialize the database: postgresql-setup initdb
Start PostgreSQL service: systemctl start postgresql
Create and deploy your Java sample application (WAR file) to the Tomcat server within the container. Ensure it's properly configured to connect to the PostgreSQL database.
To access Tomcat and PostgreSQL from your laptop, map container ports to your local machine.
Stop the running container: docker stop my-centos9
Then start it again, mapping ports: docker run -it --name my-centos9 -p 8080:8080 -p 5432:5432 centos:9
Tomcat: Open a web browser and go to http://localhost:8080 to access your Tomcat server.
PostgreSQL: Use your preferred database client to connect to localhost on port 5432 (default PostgreSQL port).
Save the modified Dockerfile in a directory.
Open a terminal, navigate to the directory containing the Dockerfile.
Run the following command to build the Docker image: docker build -t ubuntu_selenium_java .
After the image is built, you can start a container based on that image: docker run -it ubuntu_selenium_java