I've made a war to run on my tomcat server in a Docker container. The servlet runs fine in eclipse, but when I have compiled it put it in my Docker it isn't loading in the required classes properly.
Project structure and manifest file
When I try and access the servlet using my browser I get this error.
Error in browser
I went into the Docker container and checked that gurobi.jar is still in WEB-INF/lib/ and it is.
I don't know why this wouldn't be able to find the jar, as it works fine when it's in Eclipse.
docker-compose.yml
version: '3'
services:
db:
image: mysql:5.7
ports:
- '3306:3306'
environment:
MYSQL_DATABASE: 'projectdb'
MYSQL_USER: ''
MYSQL_PASSWORD: ''
MYSQL_ROOT_PASSWORD: ''
web:
build:
context: .
dockerfile: Dockerfile
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
- /var/run/docker.sock:/var/run/docker.sock
ports:
- "8000:8000"
depends_on:
- db
tomcat:
image: tomcat
ports:
- "8080:8080"
volumes:
- ./GurServ.war:/usr/local/tomcat/webapps/GurServ.war
java:
image: bitnami/java:latest
volumes:
- .:/app
- .:/code
Dockerfile
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /code
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
EXPOSE 8000
CMD exec gunicorn djangoapp.wsgi:application - bind 0.0.0.0:8000 - workers 3
Project structure
...
Java Resources
src
...
WebContent
META-INF
MANIFEST.MF
WEB-INF
gurobi-javadoc.jar
gurobi.jar
Related
I just want to deploy my springboot applicaiton on the remote centos server through the intellij idea.
First I tried the way of DockerFile to deploy the application on intellij idea and I successed.
this is my DockerFile config
FROM williamyeh/java8
# COPY or ADD to image
COPY dockerdemo-0.0.1-SNAPSHOT.jar app.jar
RUN bash -c "touch /app.jar"
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
but when I tried the method of docker-compose.yml,I failed,I can't mapped my navtive jar to the remote system.my docker-compose.yml config is
version: "3"
services:
dockerDemo2:
image: adoptopenjdk/openjdk8:latest
container_name: dockerDemo2
privileged: true
environment:
TZ: Asia/Shanghai
LANG: es_US.UTF-8
volumes:
- ./dockerdemo-0.0.1-SNAPSHOT.jar:/docker/dockerdemo-0.0.1-SNAPSHOT.jar
command: bash -c " tail -f /dev/null "
ports:
- 8080:8080
I deployed successed,but when I get in the remote docker ,I found the /docker/dockerdemo-0.0.1-SNAPSHOT.jar is a directory, It should expected as a jar file,but it not,I don't know why that.that's really confuesed me.
I've just started to use Docker and I don't know why the Wildfly's docker container doesn't have the latest files even though it copies the war. I have a JS file which I've changed things in it, but whenever I access 127.0.0.1:8080/static/js/myjs.js I still get the older one even though I've sudo mvn clean install the app and then build the image.
I've a docker-compose file which looks like this:
version: "3"
services:
app:
build:
context: .
dockerfile: ./docker/docker-app/Dockerfile
ports:
- "8080:8080"
links:
- "db:task_book_db"
depends_on:
- "db"
db:
image: mysql:5.7.22
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
- MYSQL_DATABASE=sample_db
- MYSQL_USER=sample_usr
- MYSQL_PASSWORD=sample_pw
ports:
- "3306:3306"
start_dependencies:
image: dadarek/wait-for-dependencies
depends_on:
- "db"
I do sudo docker-compose run --rm start_dependencies && sudo docker-compose up --build app and whenever I've changed something, I just stop the app container then I do sudo docker-compose up --build app again. I've read about volumes but I'm not sure how to use them yet.
As mentioned in the comments:
This issue might be because of browser cache. Try accessing the 127.0.0.1:8080/static/js/myjs.js
after clearing the cache.
I developed a Java EE application on Eclipse for a school project and try to use it in localhost through Tomcat, all using Docker.
My problem is the url, I would like that when I launch my application with Docker, I can access it at http://localhost:8080. Currently, I have to go to the link http://localhost:8080/Epitech_Dashboard/.
Would it be possible to have access to the application directly on http://localhost:8080?
Ps: I saw a similar question on slack but it does not solve my problem because she does not handle the problem with docker-compose.
Here's my Dockerfile and my docker-compose.yml
Dockerfile:
FROM java:8
EXPOSE 8080
ADD /#.war #.war
ENTRYPOINT ["java", "-jar", "#.war"]
docker-compose.yml
version: '2'
services:
web:
image: tomcat:7
environment:
JDBC_URL: jdbc:mysql://db:3306/example_db?connectTimeout=0&socketTimeout=0&autoReconnect=true
JDBC_USER: example_db_user
JDBC_PASS: example_db_pass
ports:
- '8080:8080'
volumes:
- ./Epitech_Dashboard.war:/usr/local/tomcat/webapps/Epitech_Dashboard.war
links:
- db
db:
image: mysql:latest
hostname: db
environment:
MYSQL_ROOT_PASSWORD: nimda
MYSQL_DATABASE: example_db
MYSQL_USER: example_db_user
MYSQL_PASSWORD: example_db_pass
volumes:
- ./db:/docker-entrypoint-initdb.d
Thank you in advance.
The docker container is not able to access the jar file, that is being accessed over the mount point /my/project/dir.
I am certain it is not a permission issue, because I changed the access rights locally, so it should be able to read/write/execute it.
This is the Dockerfile:
FROM tomcat:9-jre8
RUN apt-get update && apt-get install librrds-perl rrdtool -y
VOLUME ["/data/rrdtool", "/my/project/dir"]
ENTRYPOINT [ "java","-jar","/my/project/dir/build/libs/spring-project-0.1.0.jar" ]
And this is the docker-compose.yml file:
version: '2'
services:
db:
container_name: db1
image: mysql:8
restart: always
environment:
MYSQL_ROOT_PASSWORD: password123
MYSQL_USER: user123
MYSQL_PASSWORD: pasw
MYSQL_DATABASE: mydb
expose:
- "3307"
db2:
container_name: db2
image: mysql:8
restart: always
environment:
MYSQL_ROOT_PASSWORD: password123
MYSQL_USER: user123
MYSQL_PASSWORD: pasw
MYSQL_DATABASE: mydb2
expose:
- "3308"
spring:
container_name: spring-boot-project
build:
context: ./
dockerfile: Dockerfile
links:
- db:db1
- db2:db2
depends_on:
- db
- db2
expose:
- "8081"
ports:
- "8081:8081"
restart: always
This is the output from docker-compose logs spring:
Error: Unable to access jarfile /my/project/dir/build/libs/spring-project-0.1.0.jar
I don't see you copying the jar into the container anywhere. You should try moving a VOLUME declaration from Dockerfile to the compose file into the spring service like this:
volumes:
- /my/project/dir:/app
And then inside Dockerfile you should point to the dir:
ENTRYPOINT [ "java","-jar","/app/build/libs/spring-project-0.1.0.jar" ]
Later on if you'd like to deploy it (for example) you should copy the project files directly into the image instead of utilizing the volumes approach. So in Dockerfile you'd then do:
COPY . /app
instead of VOLUME [..]
Putting it all together:
development:
Dockerfile:
FROM tomcat:9-jre8
RUN apt-get update && apt-get install librrds-perl rrdtool -y
ENTRYPOINT [ "java","-jar","/app/build/libs/spring-project-0.1.0.jar" ]
compose-file:
version: '2'
services:
[..]
spring:
container_name: spring-boot-project
build: .
links:
- db:db1
- db2:db2
depends_on:
- db
- db2
ports:
- "8081:8081"
restart: always
volumes:
- /my/project/dir:/app
deployment:
Dockerfile (that is placed inside project's folder, docker build requires it's build context to be in a current directory):
FROM tomcat:9-jre8
RUN apt-get update && apt-get install librrds-perl rrdtool -y
COPY . /app
ENTRYPOINT [ "java","-jar","/app/build/libs/spring-project-0.1.0.jar" ]
compose-file:
version: '2'
services:
[..]
spring:
container_name: spring-boot-project
build: .
links:
- db:db1
- db2:db2
depends_on:
- db
- db2
expose:
- "8081"
If you are using Spring-Boot Project with Maven build. Try with below
Dockerfile.
FROM maven:3.8.4-openjdk-17 as maven-builder
COPY src /app/src
COPY pom.xml /app
RUN mvn -f /app/pom.xml clean package -DskipTests
FROM openjdk:17-alpine
COPY --from=maven-builder app/target/dockube-spring-boot.jar /app-service/dockube-spring-boot.jar
WORKDIR /app-service
EXPOSE 8080
ENTRYPOINT ["java","-jar","dockube-spring-boot.jar"]
dockube-spring-boot.jar // replace with your generated jar name
Here is the Sample Code Available
I'm trying to a selenium hub, chrome node, and firefox node, and my code that runs the test execution script in that order. I have the nodes depending on the hub and the code depending on both hubs. However, running docker-compose --build builds the code first and tries to run without starting the selenium components. I am unsure what I am doing wrong.
docker-compose.yml
version: '3'
services:
hub:
image: selenium/hub
networks:
robottestsnw: {}
ports:
- 4444:4444
chrome:
image: selenium/node-chrome
networks:
robottestsnw: {}
depends_on:
- hub
shm_size: '2g'
environment:
SCREEN_WIDTH: 1920
SCREEN_HEIGHT: 1080
HUB_HOST: hub
firefox:
image: selenium/node-firefox
networks:
robottestsnw: {}
depends_on:
- hub
shm_size: '2g'
environment:
HUB_PORT_4444_TCP_ADDR: hub
SCREEN_WIDTH: 1920
SCREEN_HEIGHT: 1080
HUB_HOST: hub
robottests:
build: .
networks:
robottestsnw: {}
depends_on:
- chrome
- firefox
networks:
robottestsnw:
driver: bridge
Dockerfile
# Dockerfile
# Base image
FROM sgrio/java-oracle
RUN apt-get update
RUN apt-get install -y maven
# Copy test project files to the image folder
COPY . /frontend-integration-tests
# Make the folder as a working directory
WORKDIR /frontend-integration-tests
# Install the test project libraries
RUN mvn package
CMD ["java", "-cp", "target/automated-testing 0.0.1-SNAPSHOT.jar", "automated-testing.service.App"]
docker-compose up
It starts services in dependency order, about docker-compose --build up don't sure. And maybe your port, network name are defined wrong:
hub:
image: selenium/hub
networks:
- robottestsnw
ports:
- 4444:4444