Skip to content

Instantly share code, notes, and snippets.

@liemle3893
Last active December 20, 2024 20:27
Show Gist options
  • Save liemle3893/025624fc02dbecc0e8fd99a40a4ae94c to your computer and use it in GitHub Desktop.
Save liemle3893/025624fc02dbecc0e8fd99a40a4ae94c to your computer and use it in GitHub Desktop.

Revisions

  1. liemle3893 revised this gist May 15, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Use can use prebuild version by using:
    ```
    $ docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    ```
    Wait for docker to pull and up. Then jump to step [#6](#test-the-result)
    Wait for docker to pull and up. Then jump to step [#6](#6-test-the-result)
    ## 1. Clone example project from Spring Boot repository
    ```
    $ git clone https://github.com/spring-guides/gs-spring-boot.git
  2. liemle3893 revised this gist May 15, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,7 @@ Use can use prebuild version by using:
    ```
    $ docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    ```
    Wait for docker to pull and up. Then jump to step #6
    Wait for docker to pull and up. Then jump to step [#6](#test-the-result)
    ## 1. Clone example project from Spring Boot repository
    ```
    $ git clone https://github.com/spring-guides/gs-spring-boot.git
  3. liemle3893 revised this gist May 15, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,9 @@
    Spring Boot + Docker Multistage = Smaller container size

    Use can use prebuild version by using:
    docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    ```
    $ docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    ```
    Wait for docker to pull and up. Then jump to step #6
    ## 1. Clone example project from Spring Boot repository
    ```
  4. liemle3893 revised this gist May 15, 2018. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # docker-multi-stage
    Spring Boot + Docker Multistage = Smaller container size

    Use can use prebuild version by using:
    docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    Wait for docker to pull and up. Then jump to step #6
    ## 1. Clone example project from Spring Boot repository
    ```
    $ git clone https://github.com/spring-guides/gs-spring-boot.git
  5. liemle3893 revised this gist May 15, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ Spring Boot + Docker Multistage = Smaller container size
    ```
    ## 2. Create Dockerfile
    ```
    $ wget
    $ wget https://gist.github.com/liemle3893/025624fc02dbecc0e8fd99a40a4ae94c/raw/7d5ed6c21fc981ce347bff5fcbea472fab988b26/Dockerfile
    ```
    ## 3. Build the image
    ```
  6. liemle3893 created this gist May 15, 2018.
    28 changes: 28 additions & 0 deletions Docker-multistage-example.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    # docker-multi-stage
    Spring Boot + Docker Multistage = Smaller container size

    ## 1. Clone example project from Spring Boot repository
    ```
    $ git clone https://github.com/spring-guides/gs-spring-boot.git
    $ cd gs-spring-boot/complete
    ```
    ## 2. Create Dockerfile
    ```
    $ wget
    ```
    ## 3. Build the image
    ```
    $ docker build -t saboteurkid/smaller-spring:1.0 .
    ```
    ## 4. Check the images
    ```
    $ docker images
    ```
    You will see something like this:

    saboteurkid/smaller-spring 1.0 f880454cde3e 23 minutes ago 99.4MB
    ## 5. Create new container that run the newly created image
    $ docker run -d -p 8080:8080 saboteurkid/smaller-spring:1.0
    ## 6. Test the result
    $ curl localhost:8080
    You will received: `Greetings from Spring Boot!`
    14 changes: 14 additions & 0 deletions Dockerfile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    FROM gradle:4.6-jdk8-alpine as compile
    COPY . /home/source/java
    WORKDIR /home/source/java
    # Default gradle user is `gradle`. We need to add permission on working directory for gradle to build.
    USER root
    RUN chown -R gradle /home/source/java
    USER gradle
    RUN gradle clean build

    FROM openjdk:8-jre-alpine
    WORKDIR /home/application/java
    COPY --from=compile "/home/source/java/build/libs/gs-spring-boot-0.1.0.jar" .
    EXPOSE 8080
    ENTRYPOINT [ "java", "-jar", "/home/application/java/gs-spring-boot-0.1.0.jar"]