I am going to install MySQL and Jdk-11 and run the jar file(spring boot project) on the container. If anyone has experience in this field, please help.
Thanks
this is my sql config
host='localhost',
port=3306,
user='root',
passwd='password',
FROM ubuntu
RUN apt-get update
RUN apt-get -y install mysql-server
RUN apt-get -y install openjdk-11-jdk
COPY target/orderCodeBackEnd-0.0.1-SNAPSHOT.jar /usr/app/
WORKDIR /usr/app
ENTRYPOINT ["java", "-jar", "orderCodeBackEnd-0.0.1-SNAPSHOT.jar"]
4
Answers
Will run the server in detached mode.
Setting up environment variables for your DB server passwords. You can define the password as you wish. For me, I set it to
secret
Port mapping, container internal port 3306 will be mapped to the port 3306 outside container.
Don’t forget to change
YOUR_DESIRED_HOSTNAME
andYOUR_LOCAL_MACHINE_IP
values if you want to establish a remote connection with the docker host machine. Usually, the hostname can belocalhost
if you are running docker on the same development machine. In such case, we don’t even need this--add-host
flag.However, if you want to access the db for your spring boot application from inside a docker container, you may have to use additional tool, docker-compose. The reason is because your host machine IP address may not work inside your docker container.
I think, this following git repository will be helpful for you to understand how to write your first docker-compose. This repository has a readme.md file, which you can take help from.
https://gitlab.com/mainul35/traver-auth
It is good practice to separate different services in independent containers, thus creating a less related architecture.
Next think, in docker hub we can find usefull, ready to use, images.
We can pull all images from command line and create all services but there is better way – docker compose. So first file, that u need is docker-compose.yml:
in this file we describe this 2 services:
Dockerfile for your app:
now you can easily start these services from the terminal
you must be in the directory where docker-compose.yml is located or specife -f parametr
The answer of @ConRed is not complete. I have done lots of changes from it in my application (which is shared here: https://github.com/Aliuken/JobVacanciesApp_Java11).
These are my final files:
docker-compose.yaml:
where:
Dockerfile:
docker-compose-start.sh:
docker-compose-stop.sh:
application.yaml:
pom.xml:
To run the application:
To stop the application: