I've been stuck on this for a good bit now and can't find the solution anywhere. I'm writing a java rest service using jersey framework, maven as a package manager hosted on a apache tomcat.
The project works perfectly fine locally. I want to dockerize the application and really struggling. I have the tomcat container up and running and when I go to the root of my application I can see the simple hello text I have. So when I go to http://xxx:8888/npmanager/ at this point I'm seeing what I expect.
Now when I try to hit any of my endpoints i.e https://xxx:8888/npmanager/api/XXX I get a 500 error:
warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for field: private org.glassfish.jersey.server.wadl.WadlApplicationContext org.glassfish.jersey.server.wadl.internal.WadlResource.wadlContext
Dockefile:
FROM tomcat:8.5.38
ADD ./target/npmanager.war /usr/local/tomcat/webapps/
CMD chmod +x /usr/local/tomcat/bin/catalina.sh
CMD ["catalina.sh", "run"]
docker-compose.yml
version: '3'
services:
tomcat-dev:
build: .
environment:
TOMCAT_USERNAME: root
TOMCAT_PASSWORD: root
ports:
- "8888:8080"
mysql-dev:
image: mysql:8.0.2
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: npmanager
volumes:
- /mysql-data:/var/lib/mysql
ports:
- "3308:3306"
Related
I was given a multy-steps task and im stuck !!
im trying to connect my Java container to my MYSQL container,but im getting 503 ERROR
HTTP ERROR 503
Problem accessing /. Reason:
Service Unavailable
docker-compose file :
version: "3.3"
services:
lavagna:
build: .
ports:
- "8080:8080"
networks:
- back_net
depends_on:
- my_db
environment:
spring.datasource.url: "jdbc:mysql://my-db:3306/lavagna"
my_db:
image: mysql:5.7
ports:
- "3306:3306"
networks:
- back_net
volumes:
- $PWD/mysql:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: 123
MYSQL_USER: eyal
MYSQL_PASSWORD: 123
networks:
back_net:
driver: bridge
I got the JAVA src files,i just used maven localy to build it and use target for the Java Dockerfile
java app dockerfile :
FROM openjdk:8-jre-alpine
EXPOSE 8080
COPY ./target/. .
COPY ./entrypoint.sh .
ENV DB_DIALECT MYSQL
ENV DB_URL jdbc:mysql://localhost:3306/lavagna
ENV DB_USER "root"
ENV DB_PASS "123"
ENV SPRING_PROFILE dev
RUN apk update \
&& apk add ca-certificates \
&& update-ca-certificates && apk add openssl
RUN chmod 774 entrypoint.sh
ENTRYPOINT [ "./entrypoint.sh" ]
I think you need a combination of comments and answers given already. Your containers are on the same network, so it appears to boil down to configuration.
In your docker file update your DB_URL to:
ENV DB_URL jdbc:mysql://my_db:3306/lavagna
If you use localhost your container will loopback to itself, and never hit the network.
In your docker-compose yml file, you have a typo in the url, try updating to:
spring.datasource.url: "jdbc:mysql://my_db:3306/lavagna"
As an aside, using depends_on does not wait for the service to be ready. It simply dictates start order as the documentation states:
There are several things to be aware of when using depends_on:
depends_on does not wait for db and redis to be “ready” before starting web - only until they have been started. If you need to wait for a service to be ready...
When I run the command docker-compose -f docker-compose.yml up my container starts normally.
In IntelliJ it appears the button to execute the container when the file docker-compose.yml is opened, When I try to upload the container directly through the * .yml file I get the error below:
Failed to deploy 'Compose: docker-compose': Sorry but parent: com.intellij.execution.impl.ConsoleViewImpl[,0,0,1188x368,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=] has already been disposed (see the cause for stacktrace) so the child: com.intellij.util.Alarm#7566093f will never be disposed.
My docker-compose.yml file:
version: 3.4
services:
api.logistics-service:
container_name: logistics-service
build: ./docker
ports:
- "8080:8080"
I had the same problem. A wrong version in docker-compose.yaml caused the error on first startup.
After fixing this it, I was not able to start any docker-compose-services anymore.
Looks like an IntelliJ bug.
In this situation just restart IntelliJ.
I am working on a personal project using Jsp / servlet so it needs tomcat to run. I created a compose docker file for mysql and I want to have tomcat inside the file and how to set it up in the IDE instead of downloading it from tomcat.apache.org and setting it up into the Intelij IDE. Can you guys help me? Thank you very much!
version: '3'
services:
db_bookstore:
image: mysql:5.7
ports:
- 3210:3306
environment:
- MYSQL_ROOT_PASSWORD=654321
- MYSQL_DATABASE=bookstore
I assume you want to have tomcat service in your Docker, right?
version: '3'
services:
db_bookstore:
...
tomcat:
image: tomcat:9.0.12
ports:
- "80:8080"
I am trying to connect my spring-boot application(REST endpoints) running in a Tomcat container with a mongo container. I am using docker-compose to link both the containers. The application was working perfectly fine. It just stopped working suddenly.
Following is my code:
Dockerfile:
FROM tomcat:9.0.13
WORKDIR /usr/local/tomcat/webapps
#COPY pom.xml .
#RUN ["mvn", "clean", "install"]
COPY /target/TestProfileManager.war .
docker-compose.yml:
version: '3'
services:
app:
container_name: VF-BACKEND
restart: always
build: .
ports:
- "8083:8080" #VF Webservice
depends_on:
- mongo
links:
- mongo
mongo:
container_name: VF-MONGO
image: mongo:4.0.2
ports:
- "27018:27017"
volumes:
- /data/vfdb:/data/db
application.properties
spring.data.mongodb.uri=mongodb://mongo:27018/tsp
If I run the application from the IDE as a standalone application, the endpoints do return the response. Only during container communication, I am getting 503. I could not find any post that answers my question.
Thanks for the help. Since, the code was working before, not pasting the classes. Let me know if I should share them as well.
It should be mongodb://mongo:27017, in service to service communication you do not need to use publish port.
It is important to note the distinction between HOST_PORT and
CONTAINER_PORT. the HOST_PORT is 27018 and the container port is
27017 . Networked service-to-service communication use the
CONTAINER_PORT
compose-networking
I have a two simple images:
#Angular image
FROM node:12.2.0
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json /app/package.json
RUN npm install
RUN npm install -g #angular/cli#7.3.9
COPY . /app
CMD ng serve
&
# Java spring (REST) image
FROM openjdk:8-jdk-alpine
VOLUME /tmp
COPY ./target/api-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar", "app.jar"]
And my docker-compose:
version: '3'
services:
web_app_speech:
image: web_app_speech
restart: always
ports:
- "4300:4200"
depends_on:
- api_speech_docker
api_speech_docker:
image: api_speech_docker
ports:
- "8080:8080"
restart: always
$> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
15c719d31861 web_app_speech "/bin/sh -c 'ng serv…" 9 minutes ago Up 9 minutes 0.0.0.0:4300->4200/tcp azure_web_app_speech_1
044fd15f07e4 api_speech_docker "java -Djava.securit…" 10 minutes ago Up 9 minutes 0.0.0.0:8080->8080/tcp azure_api_speech_docker_1
I can access my REST API from localhost:8080 and my web app from localhost:4300 without problem but when I try to perform a call from my web_app to my rest_api I have the following error:
OPTIONS http://api_speech_docker:8080/speech net::ERR_NAME_NOT_RESOLVED
I have no idea how to fix this, if you need more logs tell me !
Thanks for your help 🙏
To my understanding your REST API is being called from your browser which cannot resolve the docker service names. For different applications, I used the following solutions:
Use localhost: http://localhost:8080/speech
Works great for locally hosted projects
If hosting on the cloud, may cause other errors
or
Hit endpoint through public IP http://13.192.123.12:8080/speech
Only works if the IP address does not change
If hosting on the cloud, inbound traffic through port 8080 must be allowed as well