Before asking the question I would like to make a premise. I am not a computer scientist and I have no network experience.
I created a .war file on Windows that uses Java 11, Tomcat 9 and PostgreSQL. I have also used Spring Boot 2 and Maven but I believe this is not important for this discussion.
With my IDE and PostgreSQL installed on Windows, with Java, Tomcat, Maven downloaded on my computer I can see my application in the browser at the following address: https: // localhost: 8443 / it
On Windows to reach the database I use the following link: spring.datasource.url = jdbc: postgresql: // localhost: 5432 / databasename
These days I have installed the Ubuntu 22.04 system on vmware. Later I installed Docker on Ubuntu 22.04.
My ultimate goal is to test my .war file on Ubuntu 22.04 using Docker.
I would like to write the following link on the Linux browser: https: // localhost: 8443 / it
and see, thanks to Docker, my application as on Windows.
If it is not possible to use localhost on Linux or there is another practice, I can change direction.
Using localhost on Linux is also convenient because so I donāt have to recreate a new .war but I can use the one I use for Windows.
Iād like to build the following links and services:
https: // localhost: 8088 -> Apache Server (maybe I won't use it)
https: // localhost: 8443 -> Tomcat
https: // localhost: 5432 -> PostgreSQL
https: // localhost: 80 -> pgAdmin
(I have chosen random numbers for the doors, if it is not appropriate I can change.)
I also have another need. I would like that when I open Linux I find the Apache Server, Tomcat, PostgreSQL and pgAdmin containers all active.
I havenāt done any vmware network configuration. I installed the virtual machine and Ubuntu by pressing only on ānextā.
I wrote this code but it doesnāt work. Tomcat
/home/gi/Dropbox/SERVER/DOCKER-LINUX/Docker-Tomcat/Dockerfile
FROM tomcat:9.0.22-jdk13-openjdk-oracle
LABEL Author="Nome Cognome"
EXPOSE 8080
RUN rm -fr /usr/local/tomcat/webapps/ROOT
COPY ./*.war /usr/local/tomcat/webapps/ROOT.war
CMD ["catalina.sh", "run"]
/home/gi/Dropbox/SERVER/DOCKER-LINUX/Docker-Tomcat/tomcat_build.txt
cd /home/gi/Dropbox/SERVER/DOCKER-LINUX/Docker-Tomcat
docker build -t tomcat-eb:v.9.0.17 .
docker run -it --rm --name tomcat-eb-container -p 8888:8080 tomcat-eb:v.9.0.17
/home/gi/Dropbox/SERVER/DOCKER-LINUX/Docker-Tomcat/esercitazione.1.maven.war
http://localhost:8888/
The problems are as follows: 1) Why canāt I connect to the āgisā database with pgAdmin? 2) I would like the service to be automatically active when I open the VM? Itās possible? How can I do?
Good to know that you actual work on Windows, but want to test everything inside the Linux VM.
Now here is the thing with localhost: localhost on a docker host is local to the host, localhost inside a container is local to the container itself. Thus your list of āI want to access those services from the Linux vmā does work for published ports, BUT does not for communication amongst the containers.
I strongly suggest to create your containers using a docker compose file, as it makes the wiring easier and preserves the configuration in the file. It also creates a user defined network, which provides dns-based service discovery, which allows to communicate containers within the same user defined network, using the service or container name and the port the application is listening inside the container, to communicate with each other.
Since you donāt provide a custom network, your containers will use the default network, which does not provide service disovery. You either need to create a custom network, and use the --network parameter when creating the containers OR use --link target-container-name:alias (of course those are just placeholders for the real container name and an alias of your choice) and then address the target container either by its container-name or alias and the port the application is listending inside the target container.
Thank you very much, thatās exactly how you write. I have installed Squirrel SQL manually and am able to connect to the DBMS using localhost. To start Tomcat in bacground just use -d.
Now I try to create a new Docker project with the network you speak of. Iāll post the code by today.
I wrote this new project using Docker Compose but I am still having difficulty connecting to the database. The application starts but when I try to login it fails.
In the .war the login credentials are as follows:
Like I said: localhost inside a container is not the same localhost of another container or the localhost of the host. You need to change it to "url": "jdbc:postgresql://postgresql-postgis:5432/gis" as you namesd the service postgresql-postgis.
Also instead of hard coding the configuration you should realy adapt the intendended spring boot approach. A short google search for application.properties and/or application.yaml shoud give you plenty of blog posts that describe how itās implemented and how to override default values with environment variables. Once its implemented you simply add the environment variables to your compose file and have all the flexibility you need.
I havenāt had time to read the guide for Spring Boot yet and first Iād like to improve my script with Docker for applications built with JSTL and without Spring Boot. I wrote this new code and it works perfectly but I would like pgAdmin to automatically connect to the database inside the pg_data volume. Is it possible to do this? How you do it?
I assume you mean you want pgadmin to automaticly connect to the database from thepostgresql-postgis service. I doubt pgadmin can directly interact with the binary database files - last time I checked it was ājustā a management application that interacts with a postgres database server, not with the binary files the database server uses to store the content.
I see two options:
You wait untill someone who actualy uses pgAdmin responds to your post
You read the dockerhub description of the pgAdmin image to identify if the iamge supports it and you learn how to configure the pgAdmin service yourself.
FYI: the topic in the thread shifted again, which lowers the chances that someone who might know the answer might never see your question, as the thread title is about Docker virtual machines.