I'm running a java ee application on payara server with docker-compose, the application seems to work normally locally. But when deployed it will give a 404 on all "/api" requests. The jsp files seem to work fine.
#ApplicationPath("/api")
public class SimulationApplication extends Application {
}
Is there something that could cause this behaviour.
I already tried restarting the server and docker. And the server logs don't show anything special. The only exception that it throws is that it can't backup the domain.xml to domain.xml.bak. I have tried to start it without the domain.xml mapped but this won't fix the api.
Docker-compose
version: "2"
services:
java_ee:
container_name: 'java'
image: payara/server-full
ports:
- '8080:8080'
- '4848:4848'
links:
- 'db:db'
volumes:
- './payara/autodeploy:/opt/payara41/glassfish/domains/domain1/autodeploy'
- './payara/lib:/opt/payara41/glassfish/domains/domain1/lib'
environment:
JVM_OPTS: "-Xmx12g -Xms12g -XX:MaxPermSize=1024m"
angular:
container_name: 'angular'
image: nginx
ports:
- '80:80'
volumes:
- './angular:/usr/share/nginx/html'
db:
image: mysql
container_name: 'mysql'
command: mysqld --user=root --verbose
ports:
- "3306:3306"
environment:
MYSQL_DATABASE: "Db"
MYSQL_USER: "user"
MYSQL_PASSWORD: "pass"
MYSQL_ROOT_PASSWORD: "pass"
MYSQL_ALLOW_EMPTY_PASSWORD: "no"
I didn't know for sure if this would be better suited for serverfault, if that fits better i'll post it there.
Related
So I wrote a simple spring boot rest app. Now I need to create several containers of it and simulate a delay in some so that other's can be accessed using load-balancer (programming team recruitment task). I feel like all should be happening locally but I might be wrong. I'm a beginner programmer.
here is what I tried in docker-compose
version: '3.3'
networks:
frontend:
driver: bridge
backend:
driver: bridge
services:
haproxy:
build:
context: ./
dockerfile: HAProxyDockerfile
container_name: haproxy
restart: always
ports:
- 80:80
depends_on:
- web1_app
- web2_app
networks:
- frontend
- backend
database:
image: mysql:5.7
restart: always
environment:
- MYSQL_ROOT_PASSWORD=pass123
- MYSQL_USER=user
- MYSQL_PASSWORD=pass123
- MYSQL_DATABASE=currencyconverterdb
networks:
- backend
- frontend
web1_app:
image: spring-boot-converter
container_name: web1_app
ports:
- 8082:8080
build:
context: ./
dockerfile: Dockerfile
depends_on:
- database
environment:
- DATABASE_HOST=database
- DATABASE_USER=user
- DATABASE_PASSWORD=pass123
- DATABASE_NAME=currencyconverterdb
- DATABASE_PORT=3306
networks:
- frontend
- backend
web2_app:
image: spring-boot-converter
container_name: web2_app
ports:
- 8081:8080
build:
context: ./
dockerfile: Dockerfile
depends_on:
- database
environment:
- DATABASE_HOST=database
- DATABASE_USER=user
- DATABASE_PASSWORD=pass123
- DATABASE_NAME=currencyconverterdb
- DATABASE_PORT=3306
networks:
- frontend
- backend
Here is how I build the HAProxy container
FROM haproxy:1.8
RUN apt-get update && apt-get install -y \
inetutils-ping \
curl && \
mkdir /srv/logs && \
touch /srv/logs/haproxy
COPY ./haproxy.cfg /usr/local/etc/haproxy/haproxy.cfg
and here is what I write in haproxy.cfg
global
daemon
log /srv/logs/haproxy local0
log /srv/logs/haproxy local1 notice
defaults
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
option http-keep-alive
frontend http-in
bind :80
# springboot 1
acl host_web1 hdr(host) -i 127.0.0.1
use_backend web1_be if host_web1
backend web1_be
http-request set-header X-Forwarded-Port %[dst_port]
http-request add-header X-Forwarded-Proto https if { ssl_fc }
server node1 web1_app
server node1 web2_app
When i access localhost:80 I get 503 message with "No server is available to handle this request."
Would be thankful for any advices / solutions. I only got one day left.
The 503 "No server is available to handle this request." usually means:
your ACL does not work and you do not have a default_backend defined
your HAProxy is unable to reach any of its upstreams (servers)
your HAProxy is unable to resolve the names "web1_app" and "web2_app" and therefore is unable to reach any of its upstreams
there is no application running on port 80 of "web1_app"/"web2_app"
If you actually want to access with the name "localhost", change your ACL accordingly:
acl host_web1 hdr(host) -i localhost
For HAProxy to be able to do the matching on the host-header sent by your client.
I'm trying to run 3 containers through docker-compose, with postgres, cassandra and my webapp, which has a embedded tomcat server with some dependencies as ARP/Native. This libraries are located in a folder called "lib" at jar's same level.
I'm running a PoC on Windows 10 (using Linux containers) before moving it to a CentOS server, if it works on the PoC. I searched over the net and seems like is not an isolated problem but or I have no find the solution, or the solution showed didn't work for me. Here is my docker-compose.yml, with all the related files/folders stored at same level:
version: '3.1'
services:
fulmar-webapp:
container_name: "my-webapp"
image: openjdk:11-jre-slim
hostname: mywebapp
volumes:
- ./lib:/home/lib
- ./fulmar-1.0.1-SNAPSHOT-exec.jar:/home/mywebapp-1.0.1-SNAPSHOT-exec.jar
entrypoint:
- java
- -jar
- /home/mywebapp-1.0.1-SNAPSHOT-exec.jar
environment:
- LD_LIBRARY_PATH:/home/lib
- spring.datasource.url=jdbc:postgresql://postgresql:5432/mydb
- spring.datasource.username=postgres
- spring.datasource.password=postgres
- spring.jpa.hibernate.ddlAuto=update
network_mode: bridge
ports:
- 8443:8443
- 8080:8080
links:
- postgresql
- cassandra
postgresql:
container_name: "mydb"
image: postgres:11.1-alpine
restart: always
environment:
POSTGRES_DB: mydb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql
- postgresdata:/var/lib/postgresql/data
ports:
- 5432:5432
network_mode: bridge
cassandra:
container_name: "cassandra"
image: cassandra
ports:
- 9042:9042
network_mode: bridge
volumes:
postgresdata:
Not sure if is not properly mapping the folder with the libraries, or is not actually mounting the volume. This is exactly the Environment var I need to put in there:
Environment=LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/path/to/libraries/lib
Two results I have encountered:
1-Tomcat exception cause it can not find the libraries:
[ERROR][org.apache.catalina.util.LifecycleBase#log(175)] Failed to
initialize component [Connector[org.apache.coyote.http11.Http11AprProtocol-
8080]] | org.apache.catalina.LifecycleException: The configured protocol
[org.apache.coyote.http11.Http11AprProtocol] requires the APR/native library
which is not available
2-WARNING: The LD_LIBRARY_PATH variable is not set. Defaulting to a blank string.
Thanks you all in advance
EDIT: just let you know the once I run docker-compose up, and my app throws this exception, the container is no longer available so I'm unable to run any commands in it
You have a wrong syntax, it should be like this:
environment:
- LD_LIBRARY_PATH=/home/lib
I'm using docker-compose to run 3 containers:
My webapplication
Postgres
Cassandra
Once I use: docker-compose up
My webapp launches this exception:
com.datastax.driver.core.exceptions.NoHostAvailableException: All host(s)
tried for query failed (tried: cassandra/172.17.0.3:9042
Once all containers are running, I'm able to enter into my webapps and try to ping cassandras container before it dies (webapp container), and all packets are successfully returned so I guess there actually IS connectivity between them.
The weirdest thing is that once I got this exception:
.InvalidQueryException: Keyspace 'myKeyspace' does not exist
Which means connection has been stablished, but was before I add persistence and created the mentioned schema, but I did change nothing on my compose.yml to get this new result
Here is my docker-compose.yml:
version: '3.1'
services:
cassandra:
container_name: "cassandra"
image: cassandra
ports:
- 9042:9042
volumes:
- /home/cassandra:/var/lib/cassandra
postgresql:
container_name: "postgresql"
image: postgres:11.1-alpine
restart: always
environment:
POSTGRES_DB: mywebapp
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
#- ./startup.sql:/docker-entrypoint-initdb.d/startup.sql
- postgresdata:/var/lib/postgresql/data
ports:
- 5432:5432
mywebapp:
container_name: "mywebapp"
image: openjdk:10-jre-slim
hostname: mywebapp
volumes:
- ./lib:/home/lib
- ./mywebapp-1.0.1-SNAPSHOT-exec.jar:/home/mywebapp-1.0.1-SNAPSHOT-exec.jar
entrypoint:
- java
- -jar
- -Djava.library.path=/home/lib
- /home/mywebapp-1.0.1-SNAPSHOT-exec.jar
environment:
- LD_LIBRARY_PATH=/home/lib
- spring.datasource.url=jdbc:postgresql://postgresql:5432/mywebapp
- spring.cassandra.contactpoints=cassandra
- spring.cassandra.port=9042
- spring.cassandra.keyspace=mywebapp
#- spring.datasource.username=postgres
#- spring.datasource.password=postgres
#- spring.jpa.hibernate.ddlAuto=update+
ports:
- 8443:8443
- 8080:8080
depends_on:
- cassandra
volumes:
postgresdata:
Thank you all in advance
I am assuming your web app requires for the cassandra service to be running when it starts. You should add depends_on entry to your web app service so docker starts it only when cassandra is started
And the links entry is not necessary as docker automatically will use the service names as hostnames in the network created for this docker-compose project. Same goes for the network_type: bridge - that is the default network type, so you can omit that in your case.
Why when I am running docker-compose with the file below, and I am trying to run localhost:8080/todo-application-1.0/ I am getting internal error within is mentioned that jdbc cannot connect. But when I am running the same docker-compose file without web service I am able to connect to the database, can anyone explain to me what is wrong? How to successfully create a docker-compose or dockerfile that will copy the .war with the application and run it without any issues with the connection.
version: '3.3'
services:
database:
image: mysql:8.0
restart: always
environment:
MYSQL_DATABASE: 'todo-app'
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'admin'
MYSQL_ROOT_PASSWORD: 'admin'
ports:
- '3306:3306'
expose:
- '3306'
web:
image: tomcat
ports:
- "8080:8080"
volumes:
- ./build/libs/todo-application-1.0.war:/usr/local/tomcat/webapps/todo-application-1.0.war
I am trying to run a grails app in docker and keep running in some mysql connection problems. I can't figure out where the problem is.
This is my docker-compose file
version: "2"
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root2017
MYSQL_DATABASE: dbname
MYSQL_USER: Dbuser
MYSQL_PASSWORD: passw
grails:
depends_on:
- db
ports:
- "9001:9001"
restart: always
environment:
DB_HOST: db:3306
DB_PASSWORD: passw
volumes:
db_data:
The grails app does not start with the following error:
ERROR 18:08:05 org.apache.tomcat.jdbc.pool.ConnectionPool - Unable to create initial connections of pool.
grails_1 | com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
You will need to configure your datasource to point to "jdbc:mysql://db:3306/dbname"
You can do this with external config file for production env.
Or you can read the values for host and db name from system environments.
See Deploying grails application war to tomcat with docker and docker compose