Create a container, do the manual installation & create a docker image from container.
This approach is not sensible as the image creation process is manual & cannot be version controlled
Changes are difficult to handle
Create a docker container by writing a Dockerfile
This approach helps in maintaining versions of every change which you do
Changes will be simple as it all about changing one file & create a new version
Dockerfile is a simple plain text with a set of INSTRUCTIONS
Workflow:
Basic Steps involved in building a docker image
choose the right base image
add steps to install/configure your application
add information of ports required etc
add step which should be executed to run your application
This is exactly what we do to in terms of Dockerfile. In Dockerfile we have lot of instructions. Each instruction performs some activity. So lets look at Dockerfile instructions
Docker image has the following naming conventions <image-name>:<tag>
Select base image => tomcat with version 8 of java
download the file from url into webapps folder
This application runs on 8080 port
running this app is running tomcat
Now lets create a Dockerfile Refer Here for the changes
Lets try to create continer with gameoflife image docker container run -d -P gameoflife:1.0
Lets try to build one more image for spring pet clinic
This application just requires java to be present.
Copy the jar file and when you want to run the application execute command java -jar <package>.jar
Over here we need to worry about how to start the application.
Now lets look at steps
Try to find a image with java 8 installed
Copy the jar file into some path
Expose port 8080
While starting container execute the command java -jar
Lets use FROM, LABEL instructions as usual for copying the jar file lets use wget instruction and for running the command during container starts lets use CMD instruction