Run The Bridge

Podman 본문

Cloud/오픈소스

Podman

anfrhrl5555 2022. 2. 16. 22:45
728x90
반응형

0. 들어가기에 앞서

podman이란?

물개

podman컨테이너 작업을 위한 오픈 소스 Linux 도구
docker.io 및 quay.io와 같은 registry의 컨테이너가 포함된다.
Red Hat Enterprise Linux 8 / CentOS 8부터는 Docker 대신 Podman 
Pod라고 하는 컨테이너 및 컨테이너 그룹을 관리할 수 있는 libpod 라이브러리 기반
https://docs.podman.io/en/latest/#  ←  공식문서 링크

1.  Docker vs Podman

컨테이너를 올리기 위해서 가장 많이 사용되는 기술로는 docker가 제일 유명하다.

 

Dokcer 엔진을 통해 생성된 컨테이너를 관리하는 소프트웨어가 바로 kubernetes일 것이다.

처음 docker를 배우기 전에 아래 유튜브 영상을 먼저 봤었는데 당시에는 무엇을 뜻하는지 이해하지 못했다.
(사람들이 갑자기 박수치잖아;;;)

 

https://youtu.be/wW9CAH9nSLs

docker

docker을 사용하다가, 2017년에 Enterprise 버전을 상용화하면서 레드햇에서 또 다른 컨테이너 오픈소스 기술인 Podman을 사용하였고, 2019년 3월에 릴리스한 RedHat Enterprise Linux 8에 Podman이 추가되었다.

 

그러면 docker와 podman의 차이점에 대해 알아보자.

Docker

  • 애플리케이션을 빌드하고 컨테이너화를 위한 Docker Engine
  • 컨테이너 이미지를 배포하고 제공하기 위한 Dcoker Registry
  • 여러 개의 컨테이너를 app으로 정의하고 실행하기 위한 Docker Compose
  • 사용자의 로컬 컴퓨터나 클라우드 인스턴스에 도커 호스트를 구성하는 Docker Machine
  • 컨테이너 클러스터링 및 스케줄링을 위한 Docker Swarm

추가로 Dokcer는 이러한 작업들을 Docker daemon을 통해 수행된다. 그렇기에 Docker Daemon에 문제가 발생하면 Docker와 관련된 유틸리티들을 사용하는데 어려움이 따른다.

 

Podman

Docker와 달리 Daemon이 존재하지 않고, 커맨드로 레지스트리로부터 이미지를 받아와 저장하고, 해당 이미지를 사용하여 컨테이너를 실행한다. 이때 사용하는 것이 Podman 라이브러리로 컨테이너 간에 서로 영향을 주지 않는다.

---참고


2. Podman 설치방법

현재 docker를 사용하는 서버에서 Podman으로 바꿔본다.(CentOS 7에선 동시 지원이라 가능)

docker --version
Docker version 19.03.5, build 633a0ea

---

 # CentOS8
 yum -y install podman

---

docker가 설치되어 있으면 stop, disable으로 시스템을 중지시킨다.

systemctl stop docker
systemctl disable docker

---

podman --version
podman version 1.6.4

v.1.6.4의 릴리즈 내용은 아래 사진과 같다.


3. 설정 파일

podman을 설치하면 '/etc/containers'에 파일들이 설치된다.

/etc/containers
---
certs.d  oci  policy.json  registries.conf  registries.d  storage.conf

---

이 중에 'registries.conf' 파일에 image를 어디서 찾아서 pull 해올지 결정한다.

 [registries.search]
 registries = ['registry.access.redhat.com', 'registry.redhat.io', 'docker.io']

array형식이므로 앞에서부터 search 후 docker.io를 마지막으로 찾고 끝낸다.

root@kube-master /etc # podman pull nginx
Trying to pull registry.access.redhat.com/nginx...
  unsupported: This repo requires terms acceptance and is only available on registry.redhat.io
Trying to pull registry.redhat.io/nginx...
  unable to retrieve auth token: invalid username/password: unauthorized: Please login to the Red Hat Registry using your Customer Portal credentials. Further instructions can be found redhat.com/RegistryAuthentication
Trying to pull docker.io/library/nginx...
Getting image source signatures
Copying blob 5eb5b503b376 done
Copying blob 55de5851019b done
Copying blob 1ae07ab881bd done
Copying blob 091c283c6a66 done
Copying blob 78091884b7be done
Copying blob b559bad762be done
Copying config c316d5a335 done
Writing manifest to image destination
Storing signatures
c316d5a335a5cf324b0dc83b3da82d7608724769f6454f6d9a621f3ec2534a5a

redhat.com에서 nginx를 찾다가 인증 관련 문제가 발생해 docker.io로 넘어가서 image를 pull 받아왔다.

---

만약 사설 레지스트리가 있다면 여기에 입력해주면 된다.

[registries.search]
registries = ['docker.io', '10.60.100.70:5000', '10.60.100.70:30001']

4. 사설 레지스트리 구축

레지스트리 버전은 다음 docker hub에서 확인이 가능하다.

https://hub.docker.com/_/registry

 

Registry - Official Image | Docker Hub

We and third parties use cookies or similar technologies ("Cookies") as described below to collect and process personal data, such as your IP address or browser information. You can learn more about how this site uses Cookies by reading our privacy policy

hub.docker.com

그러면 사설 레지스트리를 구축해보고 image를 push, pull 테스트해본다.

 podman run -d --name myregistry -p 5000:5000 --restart=always registry:2

---

tag를 Node의 IP로 바꿔준다.

podman tag docker.io/library/registry:2 192.168.200.171:5000/registry:2

---

이제 registries.conf 파일을 수정한다.

[registries.search]
registries = ['192.168.200.171:5000', 'docker.io']

그리고 registry는 HTTPS 통신을 하므로 insecure 설정을 해주거나 인증서를 만들어줘야 한다.

 

우리는 '/etc/containers/registries.conf'에 insecure 옵션을 넣어준다.

[registries.insecure]
registries = ['192.168.200.171:5000']
podman search 192.168.200.171:5000/
INDEX          NAME                         DESCRIPTION   STARS   OFFICIAL   AUTOMATED
200.171:5000   192.168.200.171:5000/nginx                 0

※ 레지스트리 컨테이너는 생성됨과 동시에 컨테이너 내부 디렉터리에 마운트 되는 볼륨을 생성한다.


5. 명령어 

기본적으로 docker에서 지원하는 명령어는 모두 지원한다.

 

1. 컨테이너 생성

podman run -it ubuntu:18.04
Trying to pull docker.io/library/ubuntu:18.04...
Getting image source signatures
Copying blob 68e7bb398b9f done
Copying config dcf4d4bef1 done
Writing manifest to image destination
Storing signatures

root@c4bc3a323d86:/#

CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS  NAMES
c4bc3a323d86  docker.io/library/ubuntu:18.04  bash                  30 seconds ago  Up 27 seconds ago         heuristic_grothendieck

컨테이너를 빠져나오는 명령어

- ctrl + p + q: 컨테이너가 종료되지 않고 살아있다.

- exit: 컨테이너가 종료된다.

 

2. 이미지 다운로드

podman pull centos:7
podman pull centos:7
Trying to pull docker.io/library/centos:7...
Getting image source signatures
Copying blob 2d473b07cdd5 done
Copying config eeb6ee3f44 done
Writing manifest to image destination
Storing signatures
eeb6ee3f44bd0b5103bb561b4c16bcb82328cfe5809ab675bb17ab3a16c517c9
podman images | grep centos
docker.io/library/centos 7 eeb6ee3f44bd   5 months ago    212 MB

---

3. pull 받은 이미지 확인하는 방법

podman images

grep 명령어로 원하는 명령어를 골라올 수 있다.

---

4. 컨테이너 생성

podman create [이미지명]

podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS         PORTS  NAMES
81152006ed90  docker.io/library/centos:7      /bin/bash             5 seconds ago  Created               keen_shirley

현재 Created 상태

---

5. 컨테이너 시작

podman start [이미지명]

---

6. 컨테이너 접속

podman attach [이미지명]

---

Run명령어와 Create 명령어는 아래 사진을 참고하면 된다.

 

웬만하면 'podman run -it' 명령어를 많이 사용한다. → all in one service

 

7. 컨테이너 상세정보 확인

podman inspect [이미지명]

상세정보 출력

---

8. 컨테이너 볼륨 확인 및 생성

podman volume ls
podman volume create volume-test  # podman volume create [볼륨명]
volume-test
root@p-iskim-master ~ # podman volume ls
DRIVER   VOLUME NAME
local    volume-test

---

9. 컨테이너 네트워크 확인 및 생성

podman network ls
podman network create network_test  # podman network create [네트워크 이름]
 podman network ls
NAME              VERSION   PLUGINS
network_test      0.4.0     bridge,portmap,firewall,dnsname

---

10. 컨테이너 삭제 및 이미지 삭제

podman rm -f [이미지명]
podman rmi -f [이미지명 컨테이너 명]

---

11. 컨테이너 로그 확인

podman logs [컨테이너명]

---

이밖에 많은 명령어들이 있지만, 이 정도면 알아도 podman을 사용하는데 큰 무리는 없다.

 

그리고 podman이나 docker보다는 kubernetes로 Container를 컨트롤하는 경우가 많다.

 

※ 총정리

podman ps -a                        # 모든 컨테이너 조회
CONTAINER ID  IMAGE                           COMMAND               CREATED       STATUS                   PORTS  NAMES
8014c3714ba1  docker.io/library/ubuntu:18.04  bash                  42 hours ago  Exited (0) 42 hours ago         nice_margulis
f00cc012fbd6  docker.io/library/centos:7      /bin/bash             45 hours ago  Up 45 hours ago                 friendly_bell
00bb4f48064e  localhost/accordion/registry:2  /etc/docker/regis...  11 days ago   Up 4 days ago                   registry

podman exec -it [컨테이너 ID]       # 컨테이너 내부로 접속

podman run -it [이미지명] 		    # 컨테이너 생성, 시작, 접속
 - ex) podman run -it ubuntu:18.04
 
podman pull [이미지명]  			# 이미지 pull
 - ex) podman pull centos:7
 
podman images 						# pull 받은 이미지 확인

podman create [컨테이너ID]  		# 컨테이너 생성
 - ex) podman create centos:7
 
podman start [컨테이너ID]  			# 컨테이너 시작
 - ex) podman start centos:7
 
podman attach [컨테이너ID]  		# 컨테이너 접속
 - ex) podman attach centos:8

podman inspect [컨테이너ID]  		# 상세설명 확인

podman volume ls  					# 볼륨 목록 확인

podman volume create [이름]  		  # 볼륨 생성

podman network ls  					# 네트워크 목록 확인

podman network create [이름]  	  # 네트워크 생성

podman rm -f [컨테이너ID]			# 동작중인 컨테이너 삭제

podman rmi -f [IMAGE ID]		    # pull 받은 이미지 삭제

podman logs [컨테이너ID]			# 컨테이너 log 확인

6. podman의 용도

Podman을 사용함으로써 컨테이너를 쉽게 찾고, 실행하고, 빌드하고 공유할 수 있다.

 찾기

  • 내부 레지스트리 서버인 dockerhub.io 또는 quay.io에서 컨테이너를 찾든 공급업체에서 직접 찾든 몇 가지 podman search 및 podman pull 명령을 사용하면 쉽게 찾을 수 있다.

실행

  • 전체 애플리케이션을 실행하는 데 필요한 모든 것이 포함된 미리 빌드된 이미지를 사용하거나 podman run 명령 을 사용하여 Linux 배포 기본 이미지에서 시작하기 쉽다.

빌드

  • podman 빌드를 사용하면 약간의 조정으로 새 레이어를 만들거나 주요 점검을 쉽게 수행할 수 있다.

공유


7. buildah

Buildah는 CRI-O에서 image를 build 할 때 docker의 종속성을 제거하기 위해 개발되었으며 Dockerfile 없이 다른 스크립트 언어를 사용해 컨테이너 이미지를 빌드하는 것을 목표로 한다.(Dockerfile도 당연히 지원)

OCI 컨테이너 이미지에서 build 와 push 역할을 맡은 툴로 개발되었다.

yum -y install buildah  # 설치 

buildah --version  # 버전확인

간단한 예제를 통해 buildah의 build 방법과 onbuild 명령에 대한 차이점을 알아본다.

(https://github.com/containers/buildah/blob/main/docs/tutorials/03-on-build.md)

cat << EOF > Dockerfile
FROM fedora:latest
RUN touch /foo
ONBUILD RUN touch /bar
EOF
  • buildah를 사용한 build 명령을 사용한다.
buildah build-using-dockerfile -t onbuild-image --format=docker -f Dockerfile  .

STEP 1: FROM fedora:latest
STEP 2: RUN touch /foo
STEP 3: ONBUILD RUN touch /bar
STEP 4: COMMIT onbuild-image
Getting image source signatures
Copying blob 389adea752cd skipped: already exists
Copying blob 32aaaa9276c4 done
Copying config 1236c96869 done
Writing manifest to image destination
Storing signatures
1236c96869b9e33c53f0249ab3d2cf2c5de07d7675c4258ff7fb38af4b686983
1236c96869b9e33c53f0249ab3d2cf2c5de07d7675c4258ff7fb38af4b686983
  • --format=docker 라는 명령어가 존재하지 않으면, ONBUILD 명령에서 오류가 발생한다.
buildah bud -t onbuild-image -f Dockerfile .

STEP 1: FROM fedora:latest
STEP 2: RUN touch /foo
STEP 3: ONBUILD RUN touch /bar
STEP 4: COMMIT onbuild-image
ERRO ONBUILD is not supported for OCI image format, RUN touch /bar will be ignored. Must use `docker` format
  • bud 와 build-using-dockerfile은 동일한 명령이다.
  • dockerfile에서 onbuild 명령을 사용할 시 '--format=docker’ 옵션을 준다.

더 자세한 정보는 아래의 github에 방문하면 더 많이 알 수 있다.

 

https://github.com/containers/buildah

 

GitHub - containers/buildah: A tool that facilitates building OCI images.

A tool that facilitates building OCI images. Contribute to containers/buildah development by creating an account on GitHub.

github.com

 

https://github.com/containers/podman#buildah-and-podman-relationship

 

GitHub - containers/podman: Podman: A tool for managing OCI containers and pods.

Podman: A tool for managing OCI containers and pods. - GitHub - containers/podman: Podman: A tool for managing OCI containers and pods.

github.com


7. 업데이트 별 기능 차이

podman은 현재 4.0.0(2022. 02. 19 기준)까지 릴리즈 되었다.

 

계속해서 릴리즈가 나오고 있으며, docker의 모든 기능을 담아내려고 노력하고 있다.

 

현재 내가 쓰고 있는 Podman은 1.6.4 버전으로 docker는 19.03.5 버전을 사용하고 있다.

 

각 버전에서 다음 명령어의 지원유무가 다르다.

podman container prune --help
Remove all stopped containers

Description:

        podman container prune

        Removes all exited containers


Usage:
  podman container prune [flags]

Flags:
  -f, --force   Force removal of a running container.  The default is false
docker container prune --help

Usage:  docker container prune [OPTIONS]

Remove all stopped containers

Options:
      --filter filter   Provide filter values (e.g. 'until=<timestamp>')
  -f, --force           Do not prompt for confirmation

docker에서는 filter를 지원하고, podman에서는 filter를 지원하지 않는다.

prune 기능은 STOP 된 컨테이너를 전부 삭제해주는 기능이다.

 

자세한 기능은 docker.docs에서 확인이 가능하다.

https://docs.docker.com/engine/reference/commandline/container_prune/

 

docker container prune

docker container prune: Removes all stopped containers.

docs.docker.com

 

이러한 차이점이 존재하기 때문에 항상 릴리즈 노트에 나오는 최신 버전을 사용하자

 

prune 명령은 v1.7.0-RC1부터 지원한다.

 

https://github.com/containers/podman/releases?page=7


8. issue

위에서 소개했듯이 podman은 build 용도로 사용하지 않는다. build는 buildah를 이용하는데, podman으로 build를 하면 가끔 build가 되지 않는 이슈가 있다고 한다. 

 

build를 하면 특정 layer를 가져올 수 없는 버그인데.....재현이 되질않는다 ㅎㅎ

 

https://bugzilla.redhat.com/show_bug.cgi?id=1826559 

 

1826559 – Podman builds bad container images: invalid tar header error

12 users (show) akaris bbaude debarshir dwalsh ikavalio jnovy lsm5 mheon quent.haas rh.container.bot santiago tomek

bugzilla.redhat.com

현재 3.1이상 버전의 podman에서는 fix가 된 상황으로 보인다.


참고자료

[컨테이너 기술]

https://naleejang.tistory.com/227?category=458005

 

컨테이너 기술:: Docker와 Podman

안녕하세요~!! 다들 어떻게 지내고 계시나요? 저는 얼마전까지 오픈스택 관련 프로젝트를 하다가 얼마전부터 컨테이너와 관련된 일을 하기 시작했어요. 그래서, 컨테이너에 대한 관심도가 매우

naleejang.tistory.com

 

[컨테이너 역사]

https://naleejang.tistory.com/228

 

컨테이너 역사

지난 포스팅에서 우리는 컨테이너 대표 기술은 Docker와 레드햇의 새로운 컨테이너 기술인 Podman에 대해 알아보았습니다. 이번에는 언제부터 컨테이너 기술이 사용되었고, 어떻게 발전해서 지금

naleejang.tistory.com

 

[Podman docs]

https://docs.podman.io/en/latest/Introduction.html

 

Introduction — Podman documentation

Introduction Containers simplify the production, distribution, discoverability, and usage of applications with all of their dependencies and default configuration files. Users test drive or deploy a new application with one or two commands instead of follo

docs.podman.io


감사합니다.

728x90
반응형

'Cloud > 오픈소스' 카테고리의 다른 글

docker Rotary  (0) 2022.02.23
harbor  (0) 2022.02.22
CRI-O project  (0) 2022.02.21
ArgoCD 구축해보기  (0) 2021.12.28
(Storage) Ceph Storage 구축해보기  (0) 2021.12.26
Comments