|
2 | 2 |
|
3 | 3 | 1. Navigate to the directory and run the below maven command to build the war file as
|
4 | 4 | ```
|
5 |
| -mvn clean verify |
| 5 | +$mvn clean verify |
| 6 | +
|
| 7 | +[INFO] Scanning for projects... |
| 8 | +[INFO] |
| 9 | +[INFO] ------------------------------------------------------------------------ |
| 10 | +[INFO] Building Example 0.0.1-SNAPSHOT |
| 11 | +[INFO] ------------------------------------------------------------------------ |
| 12 | +[INFO] |
| 13 | +[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Example --- |
| 14 | +[INFO] |
| 15 | +[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Example --- |
| 16 | +[INFO] Using 'UTF-8' encoding to copy filtered resources. |
| 17 | +[INFO] skip non existing resourceDirectory /Users/prem/Desktop/codebase/java-maven-sample-war/src/main/resources |
| 18 | +[INFO] |
| 19 | +[INFO] --- maven-compiler-plugin:3.2:compile (default-compile) @ Example --- |
| 20 | +[INFO] Changes detected - recompiling the module! |
| 21 | +[INFO] Compiling 1 source file to /Users/prem/Desktop/codebase/java-maven-sample-war/target/classes |
| 22 | +[INFO] |
| 23 | +[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ Example --- |
| 24 | +[INFO] Using 'UTF-8' encoding to copy filtered resources. |
| 25 | +[INFO] skip non existing resourceDirectory /Users/prem/Desktop/codebase/java-maven-sample-war/src/test/resources |
| 26 | +[INFO] |
| 27 | +[INFO] --- maven-compiler-plugin:3.2:testCompile (default-testCompile) @ Example --- |
| 28 | +[INFO] No sources to compile |
| 29 | +[INFO] |
| 30 | +[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ Example --- |
| 31 | +[INFO] No tests to run. |
| 32 | +[INFO] |
| 33 | +[INFO] --- maven-war-plugin:2.5:war (default-war) @ Example --- |
| 34 | +[INFO] Packaging webapp |
| 35 | +[INFO] Assembling webapp [Example] in [/Users/prem/Desktop/codebase/java-maven-sample-war/target/Example-0.0.1-SNAPSHOT] |
| 36 | +[INFO] Processing war project |
| 37 | +[INFO] Copying webapp resources [/Users/prem/Desktop/codebase/java-maven-sample-war/src/main/webapp] |
| 38 | +[INFO] Webapp assembled in [69 msecs] |
| 39 | +[INFO] Building war: /Users/prem/Desktop/codebase/java-maven-sample-war/target/Example-0.0.1-SNAPSHOT.war |
| 40 | +[INFO] ------------------------------------------------------------------------ |
| 41 | +[INFO] BUILD SUCCESS |
| 42 | +[INFO] ------------------------------------------------------------------------ |
| 43 | +[INFO] Total time: 3.698 s |
| 44 | +[INFO] Finished at: 2018-10-31T20:12:34+05:30 |
| 45 | +[INFO] Final Memory: 16M/139M |
| 46 | +[INFO] ------------------------------------------------------------------------ |
6 | 47 | ```
|
7 | 48 | Once the above is completed the file Example-0.0.1-SNAPSHOT.war will be created under target/ folder
|
8 | 49 |
|
9 | 50 | 2. Now its time for docker, first build the docker image as below command, make sure you are running from the directory which have Dockerfile, otherwise add the dockerfile with path and name in the command too
|
10 | 51 | ```
|
11 |
| -docker build -t tomcat-sample:1.0 . |
| 52 | +$docker build -t tomcat-sample:1.0 . |
| 53 | +
|
| 54 | +Sending build context to Docker daemon 271.9kB |
| 55 | +Step 1/2 : FROM tomcat:8.0.20-jre8 |
| 56 | + ---> e88a065848be |
| 57 | +Step 2/2 : COPY target/Example-0.0.1-SNAPSHOT.war /usr/local/tomcat/webapps/sample.war |
| 58 | + ---> 68da124851e4 |
| 59 | +Successfully built 68da124851e4 |
| 60 | +Successfully tagged tomcat-sample:1.0 |
12 | 61 | ```
|
13 | 62 | 3. Start the above created image with the below docker command
|
14 | 63 | ```
|
15 |
| -docker run --name tomcat -it --rm -d -p 8080:8080 tomcat-sample:1.0 |
| 64 | +$docker run --name tomcat -it --rm -d -p 8080:8080 tomcat-sample:1.0 |
16 | 65 | ```
|
17 | 66 | 4. Navigate to http://localhost:8080/sample/ to check the started docker image with above created war file.
|
18 | 67 |
|
|
0 commit comments