I have created a docker image for my spring boot app "payalbnsl/shoppingapp"
First i start the container for mongodb: "docker run -d -p 27017:27017 --name mongodb --network n1 -e MONGO_INITDB_ROOT_USERNAME=mongodb -e MONGO_INITDB_ROOT_PASSWORD=mongodb -e MONGO_INITDB_DATABASE=levent -e MONGO_USERNAME=mongodb -e MONGO_PASSWORD=mongodb mongo --auth"
Then i run the image : "docker run -d --network n1 -p 9000:9000 payalbnsl/shoppingapp:1"
When i try to access the url "http://13.233.154.209:9000", it redirects to "http://13.233.154.209:9000/products", like it should as coded. But i keep getting 404 error. No page is displayed.
Logs are exactly same both when running locally and on ec2 using docker
But locally i can see the web page
While running on ec2, i get this page:
Though i just entered http://13.233.154.209:9000, it redirects to http://13.233.154.209:9000/products on production, but i don't see any web page.
I have opened up port 9000 for ec2 instance.
Why there is 404, i cannot understand. I am using JSP for frontend.
Application has successfully connected to mongo. Both are on bridge network n1. I have enabled firewall on this port. Even if i run this application locally using docker it gives same 404. On any instance, i am getting 404.
Also for me "curl -i --unix-socket /var/run/docker.sock http://localhost/containers/json " works while "curl -i --unix-socket /var/run/docker.sock http://containers/json " gives 404. Not sure what it means exactly.
Any help would be really appreciated!
Thanks,
Payal
It was a spring boot jsp problem. I had placed jsps in the webapp folder and when i created an executable jar file, jsps were not copied. Hence created a war file and redeployed. It worked. Resolved!
Related
I have a problem with my Spring Boot Application running in Docker.
Here is my Dockerfile embedded in my app shown below.
FROM adoptopenjdk:11-jre-hotspot
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java","-jar","/app-0.0.1-SNAPSHOT.jar"]
After I run mvn clean install, I get an app-0.0.1-SNAPSHOT.jar and then define it into a Docker file
Next, I ran this command docker build -t app . I saw this container installed on my docker desktop.
After running this command docker image ls, I also saw this container in the list.
I ran this command docker run -p 9999:8080 app to run it in docker.
The container worked flawlessly after running this command (docker ps)
Next, I test any URL like http://localhost:9999/getCategoryById/1 instead of http://localhost:8080/getCategoryById/1 in Postman but I get the message (Could not send request). When I test this URL in the browser, I get the message ERR_EMPTY_RESPONSE.
I learned the container IP address via docker inspect container_id then I used http://172.17.0.2:9999/getCategoryById/1 but nothing changed.
I also checked if the IP address manages the package (ping 172.17.0.2) but I got Request timed out message.
Here is my project link : Link
How can I fix my issue?
In your application, server.port property in application.properties file, that's used to configure port for Spring Boot embedded Tomcat Server is 8082.
To access the application on the container port 8080, you'd need to override server.port property. One of the ways property can be overridden is using an environment variable like below,
docker run -e SERVER_PORT=8080 -p 9999:8080 app
where SERVER_PORT corresponds to the container port specified in -p <hostPort>:<containerPort>
Other option is to directly update the property in application.properties file like below. After the update, you can then use the same command you've used to run the docker image docker run -p 9999:8080 app
server.port= 8080
Switched to m1 mac a week ago and I cannot get my application up and running with docker because of the jboss/keycloak image not working as expected. Getting the following message from the container when trying to access localhost:8080
12:08:12,456 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-5) MSC000001: Failed to start service org.wildfly.network.interface.private: org.jboss.msc.service.StartException in service org.wildfly.network.interface.private: WFLYSRV0082: failed to resolve interface private
12:08:12,526 ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) WFLYCTL0013: Operation ("add") failed - address: ([("interface" => "private")]) - failure description: {"WFLYCTL0080: Failed services" => {"org.wildfly.network.interface.private" => "WFLYSRV0082: failed to resolve interface private"}}
12:08:13,463 ERROR [org.jboss.as] (Controller Boot Thread) WFLYSRV0026: Keycloak 12.0.4 (WildFly Core 13.0.3.Final) started (with errors) in 20826ms - Started 483 of 925 services (54 services failed or missing dependencies, 684 services are lazy, passive or on-demand)
Tried with all image versions and all behave the same. Has anyone managed to run this image without issues? Thanks
Also you can build the keycloak docker image locally, I was able to start keycloak after doing that. Here are the steps I follow;
Clone Keycloak containers repository: git clone git#github.com:keycloak/keycloak-containers.git
Open server directory (cd keycloak-containers/server)
Checkout at desired version, eg. git checkout 12.0.4
Build docker image docker build -t jboss/keycloak:12.0.4 .
Run Keycloak docker run --rm -p 9080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin jboss/keycloak:12.0.4
Using this image, I am now able to startup keycloak. https://hub.docker.com/r/wizzn/keycloak
For Keycloak 16, docker 20.10 and docker-compose 1.29, this image works flawlessly: https://hub.docker.com/r/sleighzy/keycloak - as suggested by #zakjan.
A service like:
keycloak:
image: sleighzy/keycloak
environment:
... your Keycloak config
Should be enough to get up and running.
I'm on an m1 and I ran this and it worked.
docker run --platform=linux/amd64 -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin quay.io/keycloak/keycloak:17.0.0 start-dev
I merely add --platform=linux/amd64 to their docker command I found in https://www.keycloak.org/getting-started/getting-started-docker
The location for building a quarkus version of keycloak has changed, so this method will not work anymore for any major releases greater than 16. But the following script will. Just save it as an sh. file and execute it in your terminal. By enabling the last line, this will also directly start an instance of Keycloak.
The version number can be changed, but this is only tested for M1 chips and version 17.0.0.
VERSION=17.0.0 # set version here
cd /tmp
git clone git#github.com:keycloak/keycloak.git
cd keycloak/quarkus/container
git checkout $VERSION
docker build -t "quarkus-keycloak:$VERSION" .
#docker run -p 8080:8080 -e KEYCLOAK_ADMIN=admin -e KEYCLOAK_ADMIN_PASSWORD=admin "quarkus-keycloak:$VERSION" start-dev --http-relative-path /auth
There is an update to this issue - images for AMD64 and ARM64 architectures are now available and can be found here: https://quay.io/repository/keycloak/keycloak?tab=tags.
Ref the discussions in Github (https://github.com/keycloak/keycloak-containers/issues/341 and https://github.com/keycloak/keycloak/issues/8825).
jboss/keycloak not supported arm64 for now.
But you can use that image on docker hub: mihaibob/keycloak
https://hub.docker.com/r/mihaibob/keycloak
I'm using this and haven't difference.
I don't have a mac but I just started working with jboss/keycloak lately and have been able to get it to start.
Essentially what I did (assuming docker is installed):
docker pull jboss/keycloak:16.1.0
docker run --env-file targetDB.txt -p 8080:8080 jboss/keycloak:16.1.0
Might have to do those commands with sudo
This pulls the jboss/keycloak image from docker hub and then it runs it exposing the port 8080 within the container to the host machine. It also uses the environment variables in the .txt file (which contains info on the database endpoint you wish to connect keycloak to to persist data).
If you don't specify --env-file <text file> I believe keycloak uses its default h2 Database which isn't the best.
I have my local jboss/keycloak pointing to an postgres db I have in an AWS RDS environment, so the contents of the targetDB.txt for me is:
DB_VENDOR=postgres
DB_ADDR=<my postgres aws rds endpoint>:5432
DB_DATABASE=<name of the database>
DB_USER=<db username to connect to postgres instance>
DB_PASSWORD=<password associated with db username to connect>
If I'm not mistaken the name of the Database in DB_DATABASE field must already exist. So you'll need to create that before running the docker run command.
After you do the docker run command above and the logs show it starting up you should be able to access the keycloak admin console on your local browser:
http://localhost:8080/auth
If this is the first time you're running keycloak you have to create a master/admin user before you can log in.
To add a master user, run these commands (while your keycloak is already running):
docker exec <container id or container name> /opt/jboss/keycloak/bin/add-user-keycloak.sh -u <USERNAME> -p <PASSWORD>
then you need to restart your keycloak container:
docker restart <container id or container name>
Again you might have to do those commands with sudo.
After thats done, go back to your local web browser http://localhost:8080/auth and you can now access the login page and actually login with the username and password you created above.
This is driving me crazy:
I created a new .Net Core Web App from VS2019, adding support for docker (linux containers).
Everything works fine: if I start the debugger from VS the image is built, the container is started and the web app is available at http://localhost:32772/weatherforecast.
Then I clean it all up, and try to build and run manually:
docker build -t webapp2 --file webapplication2/Dockerfile .
docker run --name webapp2 -p 5000:5000 -t webapp2
(or even docker run --name webapp2 -p 5000:5000 -e "ASPNETCORE_ENVIRONMENT=Development" -t webapp2)
Build runs successfully, and (apparently) run command works fine too:
But...surprise...This way I cannot reach the app anymore (at http://localhost:5000/weatherforecast)!
Tried almost anything, use internal ip address from inspect, changing ports and run commands, adding -e "ASPNETCORE_URLS=https://+:443;http://+:80", nothing seems to work.
So the question is: what kind of magic we have behind the VS debug command?
I tried to see what's there but I don't see anything useful:
docker run -dt -v "C:\Users\carlo\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Progetti\prove\docker\API\WebApplication2:/app" -v "C:\Progetti\prove\docker\API:/src/" -v "C:\Users\carlo\.nuget\packages\:/root/.nuget/fallbackpackages2" -v "C:\Program Files\dotnet\sdk\NuGetFallbackFolder:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true" -e "ASPNETCORE_ENVIRONMENT=Development" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages2" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages;/root/.nuget/fallbackpackages2" -P --name WebApplication2 --entrypoint tail webapplication2:dev -f /dev/null
Thanks!
Passing the port to docker run doesn't somehow override the port he application is running on. All you're saying is that you want port 5000 on the container exposed as port 5000 on the network. However, you app is running on 80, so that buys you nothing. You'd need -p 80:5000.
The ASPNETCORE_URLS environment variable is just way to configure the URLs of your app, which in a container is going to bind to https://+:443;http://+:80 by default. Setting the environment variable to the same thing again does nothing. You could do something like http://+:5000, which would then change the internal port to 5000 instead of 80, and then your original docker run command would have worked, because there's something actually running on port 5000.
I start rabbitmq on docker with command:
docker run -d --hostname my-rabbit --name rabbit-fox -p 5672:5672 -p 8090:15672 rabbitmq:3-management
it runs fine and i can log into console, but later on Chrome browser i get this:
and can not use then console in the browser.
Clearing browser's cache & memory did the work in my case.
After facing the same issue these steps performed:
I tried to re-run the docker, even I got to the point I re-installed the RabbitMQ server image without any result.
It simply was solved when I cleared the browser's Cache & Memory
I have a simple Spring Boot Application, a Spring Cloud Config Server that is going to be run on Openshift 3.1. The problem is that when running on this platform, the application increases its size steadily until it uses up the set up container max memory (512MB), crashing eventually, and making Openshift restart it.
We configure this application on Openshift with a Dockerfile. Deploying it directly on a simple Docker container the application behaves normally. I load-tested it with JMeter and its memory compsumption stays at 256MB, no matter the load.
Could this be an Openshift bug? Is there any solution for this?
Dockerfile:
FROM java:8
RUN curl -H 'Cache-Control: no-cache' -f "http://${APPLICATION-URL}" -o ./app.jar
EXPOSE 8888
ENTRYPOINT java -jar ./app.jar