Widget Connector | ||
---|---|---|
|
Info | ||||
---|---|---|---|---|
| ||||
|
application.properties
- Docker Container화를 하면 Redis는 다른 Container에 존재하므로, host와 port를 명시해야 합니다.
Code Block | ||
---|---|---|
title | src/main/resources/application.properties||
## Redis 설정을 추가 합니다.
[root@workspace-vm my-reactive-link-shortener-sample-app]# cat src/main/resources/application.properties
## host 와 port를 추가 합니다.
spring.redis.host=redis
spring.redis.port=6379 |
Dockerfile
Code Block | ||
---|---|---|
| ||
FROM maven:3.6.53-jdkopenjdk-8-slim AS build WORKDIR /usr/app COPY . /usr/app COPY pom.xml /usr/app RUN mvn clean package -Dmaven.test.skip=true FROM openjdk:8-jdkjre-alpine COPY --from=build /usr/app/target/*.jar /app.jar EXPOSE 8080 ENTRYPOINT ["java","-jar","/app.jar"] |
Docker Image Build
Code Block |
---|
## Docker images를 생성합니다. [root@workspace-vm my-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 my-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 my-reactive-link-shortener-sample-app]# |
Docker Image Tag
Code Block |
---|
## Docker image tag를 추가 합니다. [root@workspace-vm my-reactive-link-shortener-sample-app]# docker tag reactor-demo:1.0 sooabia/reactor-demo:1.0 [root@workspace-vm my-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
Code Block |
---|
## Docker hub에 push 합니다. [root@workspace-vm my-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 my-reactive-link-shortener-sample-app]# [root@workspace-vm my-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 sanse-reactive-link-shortener-sample-app]# |
Docker Container실행 of DockerHubImage
Code Block |
---|
## Docker 이미지로 어플리케이션 실행 [root@workspace-vm my-reactive-link-shortener-sample-app]# docker run -d -p 80:8080 --link redis sooabia/reactor-demo:1.0 4cef1da580aad24a586f307b31a54a202912617d09f7996777b7b2fc56dfe717 [root@workspace-vm my-reactive-link-shortener-sample-app]# ## 어플리케이션 호출 [root@workspace-vm my-reactive-link-shortener-sample-app]# curl -XPOST http://localhost/link -H "Content-Type: application/json" -d "{\"link\":\"http://wiki.iisanse.com\"}" {"shortenedLink":"http://localhost/link/gjCiOz"} |
Docker Container정리
Code Block |
---|
## Docker container 정리 [root@workspace-vm my-reactive-link-shortener-sample-app]# docker rm $(docker ps -a | awk '{print$1}') --force 4cef1da580aa 8ebd440fdd83 [root@workspace-vm my-reactive-link-shortener-sample-app]# docker ps -a CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES |
...