Dockerfile
Dockerfile
FROM maven:3.6.3-openjdk-8-slim AS build WORKDIR /usr/app COPY . /usr/app RUN mvn clean package -Dmaven.test.skip=true FROM openjdk:8-jre-alpine COPY --from=build /usr/app/target/*.jar /app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"]
maven:3.5-jdk-8
openjdk:8-jdk-alpine
Docker Image Build
## Docker images를 생성합니다. [root@workspace-vm reactive-link-shortener-sample-app]# docker build -t reactor-demo:1.0 . Sending build context to Docker daemon 25.35MB Step 1/4 : FROM openjdk:8-jdk-alpine 8-jdk-alpine: Pulling from library/openjdk bdf0201b3a05: Pull complete 9e12771959ad: Pull complete 018b76c3c533: Pull complete Digest: sha256:ced4c16db19a0c7a813bb33ba379b7f7fdf48ce096c57750eb911b4bd928ffa9 Status: Downloaded newer image for openjdk:8-jdk-alpine ---> ece449e0acb8 Step 2/4 : COPY target/*.jar app.jar ---> 274a6f613050 Step 3/4 : EXPOSE 8080 ---> Running in b540382aa918 Removing intermediate container b540382aa918 ---> f2236a423d06 Step 4/4 : ENTRYPOINT ["java","-jar","/app.jar"] ---> Running in 508bf9cdfdaf Removing intermediate container 508bf9cdfdaf ---> cb99c11f4409 Successfully built cb99c11f4409 Successfully tagged reactor-demo:1.0 [root@workspace-vm reactive-link-shortener-sample-app]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE reactor-demo 1.0 cb99c11f4409 10 seconds ago 130MB openjdk 8-jdk-alpine ece449e0acb8 12 hours ago 105MB redis latest a55fbf438dfd 5 weeks ago 95MB quay.io/testcontainers/ryuk 0.2.2 527073eb32d1 15 months ago 9.31MB redis 4.0.2 8f2e175b3bd1 18 months ago 107MB [root@workspace-vm reactive-link-shortener-sample-app]#
Docker Image Tag
## Docker image tag를 추가 합니다. [root@workspace-vm reactive-link-shortener-sample-app]# docker tag reactor-demo:1.0 sooabia/reactor-demo:1.0 [root@workspace-vm reactive-link-shortener-sample-app]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE reactor-demo 1.0 cb99c11f4409 About a minute ago 130MB sooabia/reactor-demo 1.0 cb99c11f4409 About a minute ago 130MB openjdk 8-jdk-alpine ece449e0acb8 12 hours ago 105MB redis latest a55fbf438dfd 5 weeks ago 95MB quay.io/testcontainers/ryuk 0.2.2 527073eb32d1 15 months ago 9.31MB redis 4.0.2 8f2e175b3bd1 18 months ago 107MB
Docker Hub에 Push
## Docker hub에 push 합니다. [root@workspace-vm reactive-link-shortener-sample-app]# docker login Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one. Username: sooabia Password: WARNING! Your password will be stored unencrypted in /root/.docker/config.json. Configure a credential helper to remove this warning. See https://docs.docker.com/engine/reference/commandline/login/#credentials-store Login Succeeded [root@workspace-vm reactive-link-shortener-sample-app]# [root@workspace-vm reactive-link-shortener-sample-app]# docker push sooabia/reactor-demo:1.0 The push refers to repository [docker.io/sooabia/reactor-demo] db9c523483cf: Pushed 560e8fc5dfa2: Mounted from library/openjdk dee6aef5c2b6: Layer already exists a464c54f93a9: Layer already exists 1.0: digest: sha256:1451d515475d33654038a8f95e37ed39b834f0b162de86876ea15718741f6828 size: 1159 [root@workspace-vm reactive-link-shortener-sample-app]#
Docker Container실행 of DockerHubImage
## Docker 이미지로 어플리케이션 실행 [root@workspace-vm reactive-link-shortener-sample-app]# docker run -d -p 80:8080 --link redis sooabia/reactor-demo:1.0 4cef1da580aad24a586f307b31a54a202912617d09f7996777b7b2fc56dfe717 [root@workspace-vm reactive-link-shortener-sample-app]# ## 어플리케이션 호출 [root@workspace-vm reactive-link-shortener-sample-app]# curl -XPOST http://localhost/link -H "Content-Type: application/json" -d "{\"link\":\"http://wiki.iisanse.com\"}" {"shortenedLink":"gjCiOz"}
Docker Container정리
## Docker container 정리 [root@workspace-vm reactive-link-shortener-sample-app]# docker rm $(docker ps -a | awk '{print$1}') --force 4cef1da580aa 8ebd440fdd83 [root@workspace-vm reactive-link-shortener-sample-app]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES