Step 1: Create a directory ‘helloworld’.
Step 2: Navigate to ‘helloworld’ folder and clone following git repository ‘https://github.com/harikrishna553/docker_spring_boot.git’.
$mkdir helloworld
$
$cd helloworld/
$
$git clone https://github.com/harikrishna553/docker_spring_boot.git
Cloning into 'docker_spring_boot'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (8/8), done.
remote: Total 14 (delta 0), reused 14 (delta 0), pack-reused 0
Unpacking objects: 100% (14/14), done.
$
$
$ls
docker_spring_boot
Step 3: Create Dockerfile in helloworld folder.
$touch Dockerfile
$
$ls
Dockerfile docker_spring_boot
Dockerfile
FROM maven:3.5.2-jdk-8-alpine AS maven_build COPY ./docker_spring_boot /data/docker_spring_boot WORKDIR /data/docker_spring_boot RUN ["mvn", "clean", "install"] CMD ["java", "-jar", "target/dockerHello-1.jar"]
Step 4: Build the image.
Navigate to the folder where Dockerfile is located and execute the below command.
docker build -t spring_hello .
$docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
spring_hello latest baef228e1fa2 3 minutes ago 571MB
sleep_me latest 49913f3eae6d 2 hours ago 88.9MB
Step 5: Run the container by executing below command.
docker run -p 9090:1234 spring_hello
$docker run -p 9090:1234 spring_hello
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.1.6.RELEASE)
2019-08-31 15:58:54.192 INFO 1 --- [ main] com.sample.app.App : Starting App v1 on 24d1cf90bf04 with PID 1 (/data/docker_spring_boot/target/dockerHello-1.jar started by root in /data/docker_spring_boot)
2019-08-31 15:58:54.198 INFO 1 --- [ main] com.sample.app.App : No active profile set, falling back to default profiles: default
2019-08-31 15:58:55.786 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 1234 (http)
2019-08-31 15:58:55.827 INFO 1 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2019-08-31 15:58:55.827 INFO 1 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.21]
2019-08-31 15:58:55.995 INFO 1 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2019-08-31 15:58:55.995 INFO 1 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 1718 ms
2019-08-31 15:58:56.419 INFO 1 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2019-08-31 15:58:56.860 INFO 1 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 1234 (http) with context path ''
2019-08-31 15:58:56.866 INFO 1 --- [ main] com.sample.app.App : Started App in 3.231 seconds (JVM running for 3.909)
2019-08-31 15:58:59.712 INFO 1 --- [nio-1234-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet 'dispatcherServlet'
2019-08-31 15:58:59.712 INFO 1 --- [nio-1234-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet 'dispatcherServlet'
2019-08-31 15:58:59.723 INFO 1 --- [nio-1234-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 11 ms
Open the url ‘http://localhost:9090/’ in browser, you can see below kind of screen.
No comments:
Post a Comment