Container 개요 및 Docker 설치


Container 개요

컨테이너는 소프트웨어 서비스를 실행하는 데 필요한 특정 버전의 프로그래밍 언어 런타임
및 라이브러리와 같은 종속 항목과 애플리케이션 코드를 함께 포함하는 경량 패키지입니다.
  • 컨테이너는 VM보다 훨씬 더 경량입니다.
  • 컨테이너는 OS 수준에서 가상화되고 VM은 하드웨어 수준에서 가상화됩니다.
  • 컨테이너는 OS 커널을 공유하며 VM에 필요한 것보다 훨씬 적은 메모리를 사용합니다.

출처: 컨테이너란?  |  Google Cloud

 

결국 컨테이너는 가볍고 편하다

VM과 Container의 차이는 GuestOS(kernel)의 유무

그저 bin과 lib만이 필요하고 그상태에서 app을 실행한다.

그렇기에 가볍고 부팅 과정이 필요 없다.

 

Docker / Kubernetes

docker는 기본적으로는 단일노드로 컨트롤한다.

docker swarm오케스트레이션 (Ochestration) 기능을 통해서 멀티노드로 관리 가능

하지만 소규모는 괜찮지만, 대규모는 힘듦

대규모로 관리하려면 Kubernetes를 사용해야함 (Kubernetes는 ochestration의 표준이라고 불림)

대신 Kubernetes는 복잡하고 어렵다.

 

Openshift(상용) - redhat

쿠버네티스 기반이지만, 기능이 추가되고 복잡한 기능들이 간편화됨 + 기술 지원 받을 수 있음 (대신 상용이라 돈냄)


Docker 설치

linux VM(Centos, Ubuntu) 생성

vagrant로 VirtualBox에 생성

 

구성

ram 4G

nic: nat , hostonly (192.168.25.0/24)

CPU: core 2개

Disk: 30GB

vb.qui = false

 

vagrantfile / ssh_conf.sh

더보기

vagrantfile

# --- Docker Centos7 ---

Vagrant.configure("2") do |config|
	config.vm.define "docker-centos" do |cfg|
		cfg.vm.box = "centos/7" 
		cfg.vm.provider "virtualbox" do |vb|
			vb.name = "docker-centos"
			vb.cpus = 2
			vb.memory = 4096
			vb.gui = false
		end
		cfg.vm.host_name = "dcentos.example.com"
		cfg.vm.network "private_network", ip: "192.168.25.10"
		cfg.vm.provision "shell", path: "ssh_conf.sh" # ssh(putty) 접속을 위한 설정
	end

# --- Docker ubuntu ---
	config.vm.define "docker-ubuntu" do |cfg|
		cfg.vm.box = "generic/ubuntu2204" 
		cfg.vm.provider "virtualbox" do |vb|
			vb.name = "docker-ubuntu"
			vb.cpus = 2
			vb.memory = 4096
			vb.gui = false
		end
		cfg.vm.host_name = "dubuntu.example.com"
		cfg.vm.network "private_network", ip: "192.168.25.20"
		# cfg.vm.provision "shell", path: "ssh_conf.sh" - 우분투는 필요없음
	end
end

 

ssh_conf.sh

#/bin/bash
# allow ssh login with password
time=$(date "+%Y%m%d.%H%M%S")
# backup before overwriting
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config_$time.backup
sudo sed -i -e 's/PasswordAuthentication no/PasswordAuthentication yes/g' /etc/ssh/sshd_config
sudo systemctl restart sshd

putty로 접속 후 타임존 변경

vagrant@dubuntu:~$ date
Mon Mar  4 01:36:34 AM UTC 2024
vagrant@dubuntu:~$ sudo timedatectl set-timezone Asia/Seoul
vagrant@dubuntu:~$ date
Mon Mar  4 10:36:57 AM KST 2024

 

Docker 설치 - Centos7

Install Docker Engine on CentOS | Docker Docs

sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# repo 추가
sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# docker 설치
sudo systemctl enable --now docker
# docker 실행
sudo docker run hello-world
# docker가 제대로 되는 지 확인
[vagrant@dcentos ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete
Digest: sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d
Status: Downloaded newer image for hello-world:latest

Hello from Docker! # 이 메시지가 나오면 제대로 실행 되는 것임
This message shows that your installation appears to be working correctly.

 

Docker 설치 - Ubuntu

Install Docker Engine on Ubuntu | Docker Docs

# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc
# 공개키 등록

# Add the repository to Apt sources:
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
  $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
  sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
# repo 추가
sudo apt-get update
# repo 추가한 거 적용

sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
# docker 설치

sudo docker run hello-world
# docker 동작 확인
## 우분투는 설치 하자마자 바로 실행 됨 심지어 enabled가 디폴트

 

'Container > Docker' 카테고리의 다른 글

Docker Hub에 업로드하기  (0) 2024.03.06
Dockerfile 명령어, Multi-stage build  (0) 2024.03.05
Container image  (0) 2024.03.05
Docker Network  (0) 2024.03.04
Docker 설정 및 기본 명령어  (0) 2024.03.04

+ Recent posts