I am just trying to dockerize my Spring Boot app with MySQL database and at the beginning I see that I can do that by running some necessary commands as shown below:
docker pull mysql:8.0
docker network create springmysql-net
docker run --name mysqldb --network springmysql-net -e MYSQL_ROOT_PASSWORD=pass -e
MYSQL_DATABASE=employee-db -e MYSQL_USER=user -e MYSQL_PASSWORD=****** -d mysql:8.0
// update application properties:
url: jdbc:mysql://<container-name>:3306/employee-db&useSSL=false
docker build -t backend .
docker run --network springmysql-net --name backend-container -p 8080:8080 -d backend
And the Dockerfile
is as shown below:
FROM openjdk:8
ADD target/employee-api-0.0.1-SNAPSHOT.jar employee-api-0.0.1-SNAPSHOT.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "employee-api-0.0.1-SNAPSHOT.jar"]
Here is the points that I could not be sure or understand:
1. Assume that we send the jar file to the customer and want them to run the app on Docker with less effort. I think we can make all of those commands to be executed automatically. But I am not sure for which file should we use for this. Do we need Dockerfile
? Or docker-compose.yml
?
2. I also use docker-compose.yml
to create container and making necessary settings for development. But, I am not sure what is the purpose of Dockerfile
? It seems tı be also used for automation of this procedures. Any clarification pls?
3. In most of the examples, FROM openjdk:8
is used. I think it is related to that there is no JRE of Java 11. So, can it be also used as FROM openjdk:8
on Dockerfile for Java 11 or Java 17 applications?