On Windows 10, with IntelliJ Idea I built a Spring Boot application (with the help of Bootify.io).
That application connects to a Postgres Database that resides in Docker (container-postgres-1) called Bootifytwo.
With the intention of playing and practicing with GraalVM, I downloaded a Docker image from Oracle.
From the corresponding GraalVM container (container-graalvm-1) I have been able to generate the target/bootifytwo executable.
But when I try to run it, it gives me a database connection error.
I put below all the steps that I executed, and after some images.
(Note the use of a network for intercommunication between the containers; as well as the use of volumes for each of the 2 containers).
Help with resolution would be appreciated.
Copy folder C:\CODIGO\IDEA_PROJECTS\bootifytwo to C:\Volumenes-Docker\vol-graalvm-1\bootifytwo
docker network create red-postgres-graalvm-1
docker run --name contenedor-postgres-1 -p 5433:5432 --network red-postgres-graalvm-1 -v "C:\Volumenes-Docker\vol-postgres-1:/var/lib/postgresql/data" -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_DB=bootifytwo -d postgres:13.9-alpine3.17
docker run --name contenedor-graalvm-1 -it --network=red-postgres-graalvm-1 -v "C:\Volumenes-Docker\vol-graalvm-1:/app" container-registry.oracle.com/graalvm/community:ol8-java17-22.3.0-b1 bash
gu install native-image
cd bootifytwo
. ./mvnw native:compile -Pnative
docker start contenedor-graalvm-1
docker exec -it contenedor-graalvm-1 bash
./target/bootifytwo
The postgresql db runs in an other docker than your application. So you can't connect with localhost.
Change your setup to connect to contenedor-postgres-1
Related
I'm trying to dockerize MySQL and Spring Boot application however whenever I try to run my docker container and connect my docker image to the network the container automatically stops running.I'm new to docker so any help well is appreciated.
C:\Users\shawn>docker run --name mysqldb --network springboot -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=passion -e MYSQL_USER=root -e MYSQL_PASSWORD=password -d mysql:5.7
54d2a7c0ec819ec5e8e550ad61f55e8aabc7783ffad12d1ae04e79e7925d8064
C:\Users\shawn>docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
I've tried using docker starting and using docker run with a specific port but still getting the same error.
I have a project with Spring Boot, MySQL, Liquibase. I wanted to run it through Docker, and added Dockerfile:
FROM openjdk:8
VOLUME /tmp
ADD target/{name_of_project}.jar {name_of_project}.jar
RUN bash -c 'touch /{name_of_project}.jar'
EXPOSE 8080
ENTRYPOINT ["java","-jar","{name_of_project}.jar"]
Building the app like this: docker build -t {name_of_project} .
Then I added app to https://hub.docker.com/
In server (CentOS 7) I run mysql like this:
docker run -d -p 3306:3306 --name {name_of_mysql} -e MYSQL_ROOT_PASSWORD={pwd} -e MYSQL_DATABASE={db_name} mysql
Created network and connected it to mysql:
docker network create {network_name}
docker network connect {network_name} {name_of_mysql}
And finally run the app:
docker run -d -p 80:8080 --name {name_of_project} --net {network_name} -e MYSQL_HOST={name_of_mysql} -e MYSQL_ROOT={root} -e MYSQL_PASSWORD={pwd} -e MYSQL_PORT=3307 {app_name}
It works. However in 1-2 days it stops. I checked endpoints which are not connected with mysql, it works. Also cannot connect to mysql from Intellij Idea:
Saw the logs of mysql. Something like this:
Perhaps there are some kind of ways to avoid this situation or I did something wrong? For example, should I add docker-compose instead of Dockerfile?
There are so many questions like this. However there are no answers. I decided to write step by step, maybe after it, our society will help me. I hope so...
I have spring boot project with one page - Hello word!
JAR app perfectly works in a docker container.
But in my host computer docker does not want run app. Page not available.
docker ps say:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
4b34df7e3986 quality-serv "java -jar quality-s…" 21 hours ago Up 20 hours 0.0.0.0:8080->8080/tcp quality-service_con
But netstat (admin) does not find listeners on same port
App work only in the container, not in a personal computer.
I try many dif commands:
docker run -p 8080:8080 -d...
docker run --expose 9990 -p 9990:9990 -p 8080:8080 -it
docker run -d --net=host -P
docker run -it -d -p
They did not help.
Run yaml (docker-compose) with image description did not help too...
First make sure, when creating the container, the Dockerfile was exposing port 8080 EXPOSE 8080.
Then, if your application runs on port 8080, docker run -p 8080:8080 should be the command. Don't add -d by now, so you don't run detached mode and can see the logs.
I want to build and run my Java Maven web app in a docker container. I tried with a following command:
docker run -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
It correctly copies the resources, run maven clean install (successful build) and run with tomcat7-maven-plugin that is included in my pom.xml.
Everything works fine and logs are really similar to build and run locally on my windows machine:
Unfortunately on a web browser there is information "connection refused".
What could potentially cause the problem?:
- my application is windows specific and cannot run on linux?
- app is fully app and running but something wrong is with proxy configuration or port is not configured?
How can i proceed further - investigate the logs? Try to build on windows docker container?
P.S. I check IP of a container with Kitematic app for windows docker.
Possibly three issues. Once your used -w instead of -v
docker run -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
Which I assumed was a Typo while posting. Next you didn't publish the port on your machine
docker run -p 9998:9998 -it --name my_project -v "$PWD":/usr/src/my_project -w /usr/src/my_project maven:3.5.0-jdk-8 mvn clean install tomcat7:run
This would map the port 9998 (right side) from your container to the port 9998 on your localhost.
Third and last one, your INFO log says listening on localhost:9998. This is not good. Because that means your war is listening from traffic generated inside the the container only and not from outside the container. You need to configure your war so it listens on all interfaces inside the container and bind should be 0.0.0.0:9998
Is it possible to copy an existing WebSphere profile and run it on WebSphere in Docker?
I am doing some research on containerization, virtualization, etc. and am currently working with Docker. Getting WebSphere up and running on Docker is simple enough:
docker run --name wasserver -h wasserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install
What I'd like to do is use a profile from another WebSphere instance and run that on the Docker WebSphere. I have tried to do the following in an attempt to mount a directory that contains the profile in question, and to run same:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d ibmcom/websphere-traditional:install -e PROFILE_NAME=/WASDIR/profiles/myprofile1
The end result of this command is that the container is created, but does not run:
docker: Error response from daemon: oci runtime error: exec: "-e": executable file not found in $PATH
Perhaps there is a switch, setup, or other configuration I am missing here?
The last argument to docker run is the command you want to run inside the container (or the name of the image if you're running the default entrypoint / cmd). You just need to move your environment variable definition back in the command like this:
docker run -v /opt/WebSphere/WAS8_5/:/WASDIR --name myprofileserver -h myprofileserver -p 9043:9043 -p 9443:9443 -d -e PROFILE_NAME=/WASDIR/profiles/myprofile1 ibmcom/websphere-traditional:install