Section 15: 애플리케이션 배포를 위한 컨테이너 가상화 - KwangtaekJung/MSA-SpringCloud-user-service GitHub Wiki

Section 15: 애플리케이션 배포를 위한 컨테이너 가상화

  • Container Virtualizationn
  • Docker Desktop
  • Docker 실행

Vitualization

  • OS Virtualization

  • Container Virtualization

  • Dockerfile

    • Docker Image를 생성하기 위한 스크립트 파일
  • Docker Desktop

  • Docker 실행

    • PS C:\Users\kt79j> docker run -d -p 3306:3306 -e MYSQL_ALLOW_EMPTY_PASSWORD=true --name mariadb:latest
    • 로컬에 다운 받은 이미지가 없으면 Docker Hub에서 찾아서 다운로드 후 실행한다.
    PS C:\Users\kt79j> docker ps
    CONTAINER ID   IMAGE            COMMAND                  CREATED         STATUS         PORTS                    NAMES
    caad34b34657   mariadb:latest   "docker-entrypoint.s…"   5 minutes ago   Up 5 minutes   0.0.0.0:3306->3306/tcp   mariadb
    
    • PS C:\Users\kt79j> docker exec -it mariadb /bin/bash
root@caad34b34657:/# mysql -uroot -p -h127.0.0.1
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 4
Server version: 10.7.3-MariaDB-1:10.7.3+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.001 sec)

MariaDB [(none)]> exit
Bye
root@caad34b34657:/# exit
exit
PS C:\Users\kt79j>

Dockerfile for Users Microservice

  • https://hub.docker.com
  • $ ./mvnw clean compile package -DskipTests=true
  • $ docker build -t kt79jung/user-service:1.0 .
$ docker image ls
REPOSITORY                                                TAG                                                                        IMAGE ID       CREATED         SIZE
kt79jung/user-service                                     1.0                                                                        962a1ddf8182   2 hours ago     476MB
$ docker push kt79jung/user-service:1.0
The push refers to repository [docker.io/kt79jung/user-service]
7028d6a5539a: Pushed
3d3fdb9815af: Mounted from library/openjdk
08664b16f94c: Mounted from library/openjdk
9eb82f04c782: Mounted from library/openjdk
1.0: digest: sha256:7aa2b62cf1b6ed574ad8bb88fb8377200d1b5b98367ef3c143cdb2a460c9825e size: 1165