-
Ubuntu_Server_09. Jenkins 설정- 원격 통신을 위한 Docker Remote API> DevOps/Ubuntu Linux Server 구축 (완) 2023. 7. 13. 15:11
> Client 와 Daemon이 각기 다른 PC에 있는 경우, 젠킨스에서 원격으로 Docker Build, Run
본격적으로 들어가기 앞서, Docker의 구성 요소에 대해 알아보자.
이름 설명 데몬 (Daemon) - 컨테이너를 생성,실행,관리하는 백그라운드 프로세스
- Docker 데몬은 호스트 운영 체제에서 실행
- Docker API를 통해 클라이언트와 상호 작용.
- 한줄소개: 도커 그 자체클라이언트 (Cilent) -Docker 데몬과 상호 작용하기 위한 명령 줄 도구 또는 API를 제공하는 클라이언트 응용 프로그램
-CLI 를 통해 Docker 명령어를 실행하거나 Docker Remote API 를 사용하여 (HTTP RESTful API 방식)Docker와 상호 작용
- 한줄 소개: Daemon를 실행하는 위한 명령어이미지 (Images) - 컨테이너 실행에 필요한 파일 시스템과 소프트웨어 구성하는 읽기 전용 템플릿
- 독립적으로 실행될 수 있는 애플리케이션을 캡슐화하고 배포하기 위해 사용
- 이미지는 Dockerfile이라는 선언적인 구성 파일을 사용하여 빌드됨
- 한줄 소개: Docker Build 한 결과물 (템플릿)컨테이너 (Containers) - Docker 이미지를 실행하는 격리된 프로세스
- 애플리케이션과 해당 종속성을 환경으로 캡슐화하여 휴대성과 격리성을 제공
- 각 컨테이너는 자체 파일 시스템, 네트워크 인터페이스, 프로세스 공간 등을 가짐
- 한줄 소개: 이미지를 Run 한 결과물(프로세스)레지스트리 (Registry) - Docker 이미지를 저장하고 공유하기 위한 중앙 저장소
- Docker Hub는 Docker 공식 레지스트리이며, 공개 이미지 및 개인 이미지를 호스팅
- 독립적인 Docker 레지스트리를 설정하여 사용자 정의 이미지를 저장하고 관리 가능
- 한줄 소개: Docker GitHub대부분의 경우, Docker의 client 와 daemon은 같이 구성되어 있다.
하지만, 만약에 client는 컴퓨터 A에, daemon은 컴퓨터 B에 서로 다른 컴퓨터에 위치되어있는 경우에 원격으로 통신해야 한다. 이때 원격 상호 작용을 하기 위해 HTTP 기반의 API 로 통신하게 된다.
Docker Remote API를 사용하면 Docker Client나 사용자가 정의한 원격 Client에서 Docker Daemon으로 HTTP 요청을 보내고 받을 수 있다.
API 를 통해, Docker Client는 이미지 관리, 컨테이너 관리, 네트워크 관리, 볼륨 관리 등 다양한 작업을 수행할 수 있다.
Docker Client와 Daemon이 로컬 통신을 하는지, 아니면 원격통신을 하는지에 따라 통신 소켓이 구분되는데,
같은 기계안에서 통신할 때는 UNIX 소켓을 이용하여 통신하고, 원격 Daemon과 통신할 때는 TCP 소켓을 이용하여 통신한다.
기본적으로, Docker Daemon은 같은 기계라 가정하기에 UNIX 소켓으로 설정되어 있으며, 원격 통신을 통해 Docker Client 가 Daemon에 접속하기 위해서는 별도의 TCP 소켓을 설정해야 한다.
UBUNTU에서 작업 방법
- Terminal 에서 sudo vim /lib/systemd/system/docker.service 입력
- 알파벳 I 를 눌러 Insert Mode로 진입하고, 2번째 Service 항목의 ExecStart=/usr/bin/dockerd 라인에 다음과 같이 입력
- ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 -H fd:// --containerd=/run/containerd/containerd.sock
- -H unix:///var/run/docker.sock > 로컬 client접속을 허용해주는 유닉스 소켓 설정
- -H tcp://0.0.0.0:2375 >어느 ip에 있는 client들이 모두(0.0.0.0) 2375포트(Remote 사용시 Default Port)로 접근할 수 있도록 허용해주는 tcp설정
- ESC 를 눌러, 입력모드를 종료 시키고 :wq 를 입력해 저장하고 나간다.
- 설정을 마치면, docker daemon을 재시작 해준다.
> sudo vim /lib/systemd/system/docker.service 입력시 나오는 줄
[Unit] Description=Docker Application Container Engine Documentation=https://docs.docker.com BindsTo=containerd.service After=network-online.target firewalld.service containerd.service Wants=network-online.target Requires=docker.socket [Service] Type=notify # the default is not to use systemd for cgroups because the delegate issues still # exists and systemd currently does not support the cgroup feature set required # for containers run by docker ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2378 ExecReload=/bin/kill -s HUP $MAINPID TimeoutSec=0 RestartSec=2 Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd 229. # Both the old, and new location are accepted by systemd 229 and up, so using the old location # to make them work for either version of systemd. StartLimitBurst=3 # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd 230. # Both the old, and new name are accepted by systemd 230 and up, so using the old name to make # this option work for either version of systemd. StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead # in the kernel. We recommend using cgroups to do container-local accounting. LimitNOFILE=infinity LimitNPROC=infinity LimitCORE=infinity # Comment TasksMax if your systemd version does not support it. # Only systemd 226 and above support this option. TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers Delegate=yes # kill only the docker process, not all processes in the cgroup KillMode=process [Install] WantedBy=multi-user.target
이후, 이전 Chapter 에서 작업한 Jenkins로 가서 , 기존 명령어 앞에 다음과 같이 넣는다
Build > docker -H tcp://{원격 IP 주소}:2375 … 생략
Run > docker -H tcp://{원격 IP 주소}:2375 run … 생략
이렇게 되면, daemon 역할을 하려는 computer에서 docker ps 를 입력하여, 성공적으로 docker container 가 구동되는 것을 알 수 있다.
하다가 스케일이 커져 K8S까지 가는건 아니겠지 ?
'> DevOps > Ubuntu Linux Server 구축 (완)' 카테고리의 다른 글
Ubuntu_Server_10 (完). SMB ( a.k.a 삼바, Samba) 설치하여 Ubuntu, Linux 파일 공유 (0) 2023.07.13 Ubuntu_Server_08. Jenkins 설정- Front 서버 ( Git + Vue + Nginx + Docker) (0) 2023.07.13 Ubuntu_Server_07. Jenkins 설정- API 서버 (Git + Maven + Tomcat) (0) 2023.07.13 Ubuntu_Server_06. Jenkins 설치 , port 변경 , 초기 셋팅 (0) 2023.07.13 Ubuntu_Server_05. AWS Intergration (AWS RDS > Local DB) (0) 2023.06.20