왜 (나는) 도커를 도입하려고 할까?
업무를 하면서 아래와 같은 상황이 발생할 수 있다(했었다).
- 테스트 서버의 OS가 EOS 되고, 다른 OS로 변경이 필요할 때
- 특정 고객의 서버 OS가 무엇인지에 따라 솔루션이 해당 OS에 문제 없이 동작하는지 준비해야할 때
- 솔루션 설계로 여러 서비스가 실행될 때
- 등등
이러한 상황에서 개발자(?)는 아래와 같은 준비를 해야한다.
- 배포 및 테스트 서버에 명령어를 하나씩 입력해서 필요한 프로그램을 설치 및 세팅
- 아니면, 특정 OS에 맞춰 스크립트를 실행하면 설치되도록 스크립트를 작성
어떠한 방법이든 준비하는데 시간이 생각보다 많이 소요된다.
만약 준비하면서 설치에 오류가 발생하면 쉽지않다.(눈물 난다. 😂)
고생을 하면서 느낀점이 도커를 사용해서 설치하면 쉽게 되지 않을까 생각했지만,
팀에서 도커를 사용하지 않아서 도입에 고민이 되었다.
고민은 몇 개월했고 배송을 늦춘다고 하니까 Let's 도커를 외쳤다.
(내가) 고민해야 하는 부분
- 도커 컨테이너에 있는 로그를 어떠한 방법으로 보게 할 수 있을지
=> 모니터링 시스템을 구현해서 볼 수 있도록 한다. - 도커 컨테이너에 있는 로그 파일을 어떻게 가져올 수 있을지
- 팀원이 도커를 몰라도 쉽게 서비스를 실행할 수 있게 환경 세팅 구성
※ 해당 내용은 개인 노트북의 가상 머신(VM)으로 환경(Redhat - Rocky 9)을 구성해 작성했습니다. ※
Docker
Docker install
※ 도커 홈페이지 첫 화면에 Download Docker Desktop 버튼이 있지만 누르면 안된다.
Docker Desktop
Docker Desktop is a one-click-install application for your Mac, Linux, or Windows environment that lets you build, share, and run containerized applications and microservices.
Docker Desktop은 컨테이너화된 애플리케이션과 마이크로서비스를 빌드, 공유, 실행할 수 있는 Mac, Linux 또는 Windows 환경을 위한 원클릭 설치 애플리케이션입니다.
It provides a straightforward GUI (Graphical User Interface) that lets you manage your containers, applications, and images directly from your machine.
컨테이너, 애플리케이션, 이미지를 머신에서 직접 관리할 수 있는 간단한 GUI(그래픽 사용자 인터페이스)를 제공합니다.
그렇다 데스크탑용으로 GUI 에서 동작한다.
생각 없이 리눅스 CLI에서 설치를 진행하다가 안 되었다.(멍충이)
만약 윈도우나 화면이 있는 우분투 등의 OS에 설치할 예정이라면 가능하다. :)
https://docs.docker.com/desktop/
Docker Desktop
Explore Docker Desktop, what it has to offer, and its key features. Take the next step by downloading or find additional resources
docs.docker.com
Docker Engine
Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with:
Docker Engine은 애플리케이션을 빌드하고 컨테이너화하기 위한 오픈 소스 컨테이너화 기술입니다. Docker Engine은 다음을 사용하여 클라이언트-서버 애플리케이션 역할을 합니다.
- A server with a long-running daemon process dockerd.
(장기 실행 데몬 프로세스 dockerd가 있는 서버) - APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon.
(프로그램이 Docker 데몬과 통신하고 지시하는 데 사용할 수 있는 인터페이스를 지정하는 API) - A command line interface (CLI) client docker.
(명령줄 인터페이스(CLI) 클라이언트 docker)
1. 서버 OS 확인
일반적으로 서버의 OS는 CLI로 되어있을 것이다.
자신의 OS가 어떤 계열인지 찾고 거기에 맞게 설치 파일을 준비해야한다.
- OS 확인 명령어
cat /etc/*release*
2. 설치 방법 정하기
2-1) Uninstall old versions
=> 도커를 설치한 적이 있고, 설치 버전을 변경하고 싶지 않으면 실행하지 않아도 된다.
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine \
podman \
runc
2-2) Set up the repository
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo
2-3) Install Docker Engine
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
2-4) Start Docker
sudo systemctl start docker
2-5) Check Docker status
sudo systemctl status docker
2-6) Verify that the Docker Engine installation is successful
sudo docker run hello-world
https://docs.docker.com/engine/
Docker Engine
Find a comprehensive overview of Docker Engine, including how to install, storage details, networking, and more
docs.docker.com
Docker Volume
요놈 쉽지 않다.
Docker Build
도커 빌드 방법에는 Dockerfile을 사용해서 한 개씩 이미지를 만들거나 Docker Compose를 사용해서 작업하면된다.
Dockerfile
Docker can build images automatically by reading the instructions from a Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image.
Docker는 Dockerfile의 지침을 읽어 이미지를 자동으로 빌드할 수 있습니다. Dockerfile은 사용자가 명령줄에서 호출하여 이미지를 조립할 수 있는 모든 명령을 포함하는 텍스트 문서입니다.
FROM
WORKDIR
CMD
https://docs.docker.com/reference/dockerfile/
Dockerfile reference
Find all the available commands you can use in a Dockerfile and learn how to use them, including COPY, ARG, ENTRYPOINT, and more.
docs.docker.com
Docker Compose
services:
frontend:
image: example/webapp
ports:
- "443:8043"
networks:
- front-tier
- back-tier
configs:
- httpd-config
secrets:
- server-certificate
backend:
image: example/database
volumes:
- db-data:/etc/data
networks:
- back-tier
volumes:
db-data:
driver: flocker
driver_opts:
size: "10GiB"
configs:
httpd-config:
external: true
secrets:
server-certificate:
external: true
networks:
# The presence of these objects is sufficient to define them
front-tier: {}
back-tier: {}
https://docs.docker.com/compose/intro/compose-application-model/
How Compose works
Understand how Compose works and the Compose application model with an illustrative example
docs.docker.com
Docker Container
시행착오
1. json 파일을 로컬에서 수정하면 도커 컨테이너에 반영이 되도록 하기
방법: 마운트 (-v) 플래그 사용
착오과정:
- docker 볼륨 마운트를 잘못해서 컨테이너가 중단되거나, 로컬에서 수정한 내용이 반영 되지 않았다.
# DockerFile 예시
FROM python:3.9-alpine
WORKDIR /test
# 잘못된 방법
docker run -d -p 80:80 -v $(pwd)/config:/config --name testContainer
해결방법:
- DockerFile에서 WORKDIR을 /test라고 했기 때문에, 컨테이너 내부 경로 기준이 /test 부터 시작하지 않을까 생각했다.
# 제대로된 방법
docker run -d -p 80:80 -v $(pwd)/config:/test/config --name testContainer
느낀점:
- 리눅스 마운트에 대한 개념을 확실하게 이해해야한다.(여전히 부족한 것 같다.)
'회사 업무 > 기술 도입편' 카테고리의 다른 글
실시간 알림 시스템 구현 (0) | 2024.10.31 |
---|---|
[DevOps] 모니터링 시스템 도입기 with Grafana (0) | 2024.10.19 |
[기획] 설계서? 명세서? 그게 뭔데... (0) | 2024.07.12 |
[Refactoring] 국제화(Internationalization) 수정 (0) | 2024.05.10 |