Basic Dockerfile: Containerize a Simple App
To containerise any app, we need either the packaged source code or just a source code. If not in compile , first generate the .jar and then write the docker file.
- Java web application
- POM.xml
- Install mvn
- Run mvn clean package
- you will get the .jar
- Write the Docker file
- Build and run image
- see the running container
==================================
- Write the Docker file Stage 1 --> to get .jar from plain src code
- Java web application
- POM.xml
- Install mvn
- Run mvn clean package
- you will get the .jar
Stage 2 ---> 6) jre- java run time 7) .jar run 8) expose port
** Build the image **
============================================
- It is used to manage multiple services (conatiner)
- To run the container we use pre-built available images in the file, it will run the container from it.
- if image not available or need latest version app image, we can put the docker file at root directory where docker compose file is there and built image while running compose up. <>
- put environment variable in env file to refer its valae at run time.
- depends on says , make up service B only if service A is up and running.
================================================
- Pulled an image - nginx
- Pulled another image - alpine
- created a network - my-bridge-network
- run the containers using above metwork
- login to alpine and try to ping nginx container.
- ping should get reply
- now change the network type to host
- run another container call web2 using nginx and assign host network
- now try to ping web2 , it will not get any reply from alpine as both are in different network.