I am trying to run my java application (a project at my uni) in debug mode in IntelliJ with a dockerfile.
I found this tutorial:
https://www.jetbrains.com/help/idea/debug-a-java-application-using-a-dockerfile.html#create-remote-debug-config
I tried to follow each step (#create-remote-debug-configuration), but at 4:
Select the Docker configuration that runs your app (MyPassApp) and
specify the command to use when running your app in the Custom Command
field. The remote debug configuration will use this custom command
instead of the one defined in the Dockerfile. This command should
contain the -agentlib option to let the debugger attach to the
process:
java -agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005 -jar JavaPassFromConsole.jar
I don't know what any of those commands mean, so I dont know what to put in the custom command section.
This is my docker-compose.yml file:
version: '3'
volumes: mysql_data: {}
networks:
back:
services:
backend:
build:
context: '.'
dockerfile: 'docker_config/backend/Dockerfile'
depends_on:
- db
links:
- db
ports:
- 8080:8080
- 9990:9990
environment:
CONTACT_USERNAME: <XXX>
CONTACT_PASSWORD: <XXX>
networks:
- back db:
container_name: db
image: mysql:5.7
restart: always
volumes:
- mysql_data:/var/lib/mysql
command: --lower_case_table_names=1
environment:
MYSQL_DATABASE: <XXX>
MYSQL_ROOT_PASSWORD: root
networks:
- back
ports:
- 3306:3306
- 5005:5005 phpmyadmin:
depends_on:
- db
image: phpmyadmin/phpmyadmin
restart: always
ports:
- 4000:80
environment:
MYSQL_ROOT_PASSWORD: root
networks:
- back
Any help is appreciated!!
Related
Spring-boot application gets stuck on startup randomly at:
The postgres gets started then it gets stuck.
Only one log from the Java application is:
Listening for transport dt_socket at address: 8000
It's a brand new application. I am using spring-boot 2.6.6, Spring 5.3.18, JDK 17, and Hibernate 5.6.7.Final with docker-compose.
Here is my docker-compose.yml
version: '3.7'
services:
postgres:
image: postgis:11-alpine
command: postgres -c stats_temp_directory=/tmp
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=password!
- POSTGRES_USER=xxx
- POSTGRES_DB=xxx
volumes:
- ./postgres-data:/var/lib/postgresql/data
networks:
xxx-network:
fargate-xxx:
depends_on:
- postgres
links:
- postgres:postgres
image: fargate-xxx-local-build
build:
context: ""
dockerfile: Dockerfile
ports:
- 8080:8080
- 8000:8000
networks:
xxx-network:
dns:
- 8.8.8.8
- 8.8.4.4
environment:
ENVIRONMENT: ${ENVIRONMENT}
JAVA_OPTS: -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
volumes:
- ./dynamicconfig.properties:/tmp/dynamicconfig.properties
volumes: {}
networks:
xxx-network:
driver: bridge
Dockerfile
FROM amazoncorretto:17-alpine
EXPOSE 8000
COPY app.jar app.jar
ENTRYPOINT exec java ${JAVA_OPTS} -jar app.jar
BTW, I'm on M1.
My java app (backend) create some files during work. And when i make rebuild after some changes, this file deletes and my app need to create it again. How to save this files permanently? I try to create volume but it doesn't work.
This is my docker-compose config:
version: '3'
services:
examledb:
container_name: examle-docker-db
image: postgres
volumes:
- examle-docker-db:/var/lib/postgresql/data
ports:
- "5555:5432"
expose:
- "5555"
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=postgres
- POSTGRES_DB=examle
- PGDATA=/var/lib/postgresql/data/pgdata
networks:
- examle-docker-network
restart: unless-stopped
backend:
container_name: examle-docker-backend
build: ./backend
volumes:
- /var/lib/docker/volumes/example_prod_example-backend-volume/_data:/root/projects/example_PROD/backend
ports:
- "8080:8080"
- "8888:8888"
depends_on:
- examledb
networks:
- examle-docker-network
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://examle-docker-db:5432/examle
restart: unless-stopped
frontend:
container_name: examle-docker-frontend
build: ./frontend
restart: unless-stopped
command: serve -s dist/vu4y-frontend -l 4200
networks:
- examle-docker-network
nginx:
image: nginx:stable
container_name: examle-docker-nginx
ports:
- "80:80"
- "443:443"
volumes:
- ./data/nginx:/etc/nginx/conf.d
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
depends_on:
- frontend
- backend
networks:
- examle-docker-network
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\"'"
certbot:
image: certbot/certbot
restart: unless-stopped
volumes:
- ./data/certbot/conf:/etc/letsencrypt
- ./data/certbot/www:/var/www/certbot
networks:
- examle-docker-network
entrypoint: "/bin/sh -c 'trap exit TERM; while :; do certbot renew; sleep 12h & wait $${!}; done;'"
volumes:
examle-docker-db: { }
networks:
examle-docker-network:
driver: bridge
Also I try to create volume like this:
volumes:
- example-backend-volume:/root/projects/example_PROD/backend
It also doesn't work.
My docker-compose.yml layout in /root/projects/Example
Any advice will be very helpful. All files creates inside backend folder in the same category with src and pom.xml.
I solved the problem. My problem was that I don't understand how docker's volume works. I thought that need to write root where my docker app is run, but need to write any path in right path (in my case /root/projects/example_PROD/backend) and saves files in app there.
I am trying to build a local network for two services with a docker compose file.
service mysqldb - the data base for the spring boot app.
service app - the spring boot app.
this is the error i am receiving:
these are my files
Dockerfile
FROM maven:3.8.3-jdk-8
WORKDIR /mile-restoraunt-app
COPY . .
RUN mvn clean install
CMD mvn spring-boot:run
docker-compose.yml file
version: "3.8"
services:
mysqldb:
image: mysql
restart: unless-stopped
env_file: ./.env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
app:
depends_on:
- mysqldb
build: ./mile-restoraunt-app
restart: on-failure
env_file: ./.env
ports:
- $SPRING_LOCAL_PORT:$SPRING_DOCKER_PORT
environment:
SPRING_APPLICATION_JSON: '{
"spring.datasource.url" : "jdbc:mysql://mysqldb:$MYSQLDB_DOCKER_PORT/$MYSQLDB_DATABASE?useSSL=false",
"spring.datasource.username" : "$MYSQLDB_USER",
"spring.datasource.password" : "$MYSQLDB_ROOT_PASSWORD",
"spring.jpa.properties.hibernate.dialect" : "org.hibernate.dialect.MySQL5InnoDBDialect",
"spring.jpa.hibernate.ddl-auto" : "update"
}'
volumes:
- .m2:/root/.m2
stdin_open: true
tty: true
volumes:
db:
.env file
MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=thanatos
MYSQLDB_DATABASE=restaurant
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306
SPRING_LOCAL_PORT=6868
SPRING_DOCKER_PORT=8080
And this is my directory
in docker-compose.yaml for a app you specified build: ./mile-restoraunt-app, but you run your command inside the mile-restoraunt-app folder. You need to change the build folder.
I have a simple dockerized app that contains 3 services: Postgres, java (spring boot) as backend and a react frontend. Given the following docker-compose file:
version: "3.3"
services:
postgres:
image: postgres:12.2-alpine
environment:
POSTGRES_PASSWORD: password
volumes:
- dbdata:/var/lib/postgresql/data
ports:
- "25432:5432"
restart: unless-stopped
test-report:
build:
context: .
dockerfile: Dockerfile-test-report
restart: unless-stopped
environment:
SPRING_DATASOURCE_URL: jdbc:postgresql://postgres:5432/postgres
ports:
- "25000:5000"
depends_on:
- "postgres"
webclient:
build:
context: .
dockerfile: Dockerfile-webclient
ports:
- "23000:5000"
environment:
- HOST=webclient
- PORT=5000
- REPORTS_URL=http://test-report:5000/
command: "npm run serve"
volumes:
dbdata:
I cannot make react send requests to the correct URL from inside docker. Locally, adding a .env file with REPORTS_URL=http://localhost:25000/ (same java service running inside docker) works. Please see below my setupProxy.js file:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: process.env.REPORTS_URL,
changeOrigin: true,
secure: false
})
);
};
Any idea what is wrong? From docker, the response of the request is an index.html file
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