$ sudo apt -y install vim apt-transport-https dirmngr wget software-properties-common
$ sudo add-apt-repository ppa:cwchien/gradle
$ sudo sudo apt-get update
$ sudo sudo apt -y install gradle
$ gradle -v
Welcome to Gradle 7.4.2!
$ mkdir test-example
$ cd test-example
$ gradle init --dsl=groovy --type=java-application --test-framework=junit --package=com.test --project-name=test-docker-spring-boot
no 선택
$ ls
app gradle gradlew gradlew.bat settings.gradle
$ tree
.
├── app
│ ├── build.gradle
│ └── src
│ ├── main
│ │ ├── java
│ │ │ └── com
│ │ │ └── test
│ │ │ └── App.java
│ │ └── resources
│ └── test
│ ├── java
│ │ └── com
│ │ └── test
│ │ └── AppTest.java
│ └── resources
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
$ gradle build --info
BUILD SUCCESSFUL in 10s
build된 jar 파일은
/test-example/app/build/libs/app.jar 에 존재
docker web UI: https://hub.docker.com/ 에 레포지토리 생성
$ docker login
$ cd docker/Part2_Docker/Chapter02/0-docker
$ ls
Dockerfile build.gradle gradle gradlew gradlew.bat main settings.gradle src wrapper
// build
$ ./gradlew clean build // 기존의 build를 삭제하고 새로 build
$ ls
Dockerfile build build.gradle gradle gradlew gradlew.bat main settings.gradle src wrapper
build 폴더가 추가됨
$ cd build/libs
$ ls
test-docker-spring-boot-0.0.1-SNAPSHOT.jar
$ pwd
/home/ubuntu/docker/Part2_Docker/Chapter02/0-docker
$ docker build -t skybluelee/test:1.0 ./
현재 폴더의 모든 파일을 build
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
skybluelee/test 1.0 7361b62c1f86 56 seconds ago 673MB
$ docker push skybluelee/test:1.0
$ docker rmi 7361b62c1f86
image ID로 삭제
$ docker pull skybluelee/test:1.0
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
skybluelee/test 1.0 7361b62c1f86 5 minutes ago 673MB
image pull 확인
$ docker run -d -p 8080:8080 7361b62c1f86
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b40225f61f0c 7361b62c1f86 "java -jar app.jar" 5 seconds ago Up 4 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nostalgic_wescoff
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b40225f61f0c 7361b62c1f86 "java -jar app.jar" 14 minutes ago Up 14 minutes 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp nostalgic_wescoff
$ docker stop b40225f61f0c
b40225f61f0c
$ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b40225f61f0c 7361b62c1f86 "java -jar app.jar" 17 minutes ago Exited (143) 2 minutes ago nostalgic_wescoff
$ docker rm b40225f61f0c
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
skybluelee/test 1.0 7361b62c1f86 26 minutes ago 673MB
$ docker rmi 7361b62c1f86
$ pwd
/home/ubuntu/docker/Part2_Docker/Chapter02/1-jib-docker
$ ls
build.gradle gradle gradlew gradlew.bat main settings.gradle src wrapper
dockerFile이 없음
$ vi build.gradle
jib {
from {
image = 'adoptopenjdk/openjdk11:alpine-jre'
}
to {
image = 'skybluelee/jib-test'
tags = ['1.0']
}
...
to의 image와 tags를 수정
$ ./gradlew clean build --info
$ cd build/libs
$ ls
test-docker-spring-boot-0.0.1-SNAPSHOT.jar
jar 파일이 build 됨.
$ pwd
/home/ubuntu/docker/Part2_Docker/Chapter02/1-jib-docker
$ ./gradlew jib
dockerFile이 존재하지 않음에도 build 후 push한 것을 확인할 수 있음.
$ docker pull skybluelee/jib-test:1.0
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
skybluelee/jib-test 1.0 a5ead22331fe 3 minutes ago 188MB
$ docker run -d -p 8080:8080 -t skybluelee/jib-test:1.0
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
29dc990da639 skybluelee/jib-test:1.0 "java -Dspring.profi…" 2 seconds ago Up 1 second 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp festive_chandrasekhar