본문 바로가기

kubernetes

구글 스터디잼 쿠버네티스 입문반 스터디 - 01

728x90
반응형

구글 스터디잼이라는 좋은 기회를 보고 회사에 공유하여 스터디를 만들었다. 한 달 짜리 과정이라 블로그에 기록하면서 공부해보려고 한다. 

 

1. 도커란?

- 도커는 애플리케이션을 개발하고, 운영하는 오픈 플랫폼이다. 도커를 사용하면 애플리케이션을 인프라로 부터 분리할 수 있고, 인프라를 하나의 관리된 애플리케이션처럼 사용할 수 있다. 도커는 코드 운반, 테스트, 실행을 빠르게 할 수 있도록 도와주며, 코드 작성과 코드 실행의 싸이클을 줄여준다. 

도커는 애플리케이션 관리 및 배포에 도움이 되는 워크플로 및 도구와 결합하여 커널 컨테이너화 기능을 수행한다. 

도커 컨테이너들은 쿠버네티스에서 바로 직접적으로 사용될 수 있으며, 쿠버네티스 엔진에서 쉽게 돌아갈 수 있도록 한다. 

 

2. 실습

원래는 크레딧을 받아서 cloudsillsboot에서 진행해야하는데 아직 못받아서 그냥 로컬에서 했다. 

 

1) hello-world 찍어보기

docker run hello-world

위 명령어를 실행하면 아래와 같은 아웃풋을 얻는다. 

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:4e83453afed1b4fa1a3500525091dbfca6ce1e66903fd4c01ff015dbcb1ba33e
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (arm64v8)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

로컬에서 'hello-world'라는 이미지를 찾았는데 찾지 못했기 때문에, Docker Hub라고 불리는 퍼블릭 레지스트리에서 이미지를 풀 받아왔다. 그리고 나서 그 이미지로부터 컨테이너를 만들고 컨테이너를 실행한 결과 Hello from Docker! 라는 결과를 보여준다. 

 

2) docker images

docker images

위 명령어를 실행하면

REPOSITORY     TAG      IMAGE ID       CREATED       SIZE
hello-world   latest    feb5d9fea6a5   14 months ago   13.3kB

로컬에 있는 도커 이미지 리스트를 불러온다. 이미지 아이디는 SHA256 hash로 암호화되어 있다. 프로비전된, 즉 미리 구성된 도커이미지를 지정하는 필드이다. docker daemon이 로컬에서 이미지를 찾지 못하면, 퍼블릭 레지스트리에서 찾는다.

 

** docker daemon?

Docker Daemon은 도커 엔진의 백그라운드 서비스로 실행되는 서비스이다. 이 프로세스는 호스트 시스템과 상호작용하여 컨테이너의 생성, 실행, 중지 등 도커 엔진에서 수행되는 모든 작업을 관리한다. 

 

도커 데몬은 도커 클라이언트와 상호 작용하여, 클라이언트가 도커 API를 사용하여 도커 서비스를 제어하도록 한다. 호스트 운영 시스템의 시스템 리소스와 네트워크를 관리하고, 컨테이너화된 애플리케이션을 실행하는데 필요한 기능들을 제공한다. 

출처) chatGPT

 

3) docker run 로컬 이미지 실행

docker run hello-world

도커 이미지를 다시 실행시키면 이번에는 퍼블릭 레지스트리에서 다운받아 실행하는게 아니라, 내 로컬에 있는 이미지에서 실행을 시킨다. 

 

4) docker ps

docker ps

위 명령어는 현재 실행중인 도커 컨테이너 목록을 보여준다. 이미 실행을 마친 컨테이너는 보여주지 않는다. 

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

지금 실행중인 컨테이너가 없어서 목록에 아무것도 안뜬다. 

 

docker ps -a

위 -a 옵션은 전에 실행했던 컨테이너의 목록들을 보여준다. 

CONTAINER ID   IMAGE               COMMAND       CREATED          STATUS                       PORTS     NAMES
533c3216c402   hello-world         "/hello"      4 minutes ago    Exited (0) 4 minutes ago               vigorous_austin
a376fbe8ea8f   ubuntu              "bash"        5 minutes ago    Exited (127) 4 minutes ago             wonderful_lovelace
da0718fcf14d   hello-world         "/hello"      5 minutes ago    Exited (0) 5 minutes ago               exciting_spence

도커 container ID는 도커로부터 만들어진 UUID이고 컨테이너의 고유값을 의미한다. 컨테이너 Name은 랜덤으로 생성되는데, 이를 지정하고 싶으면

docker run --name [container-name] hello-world

이런 식으로 이름을 지정해줄 수 있다. 

 

 

728x90
반응형