Print
카테고리: [ Cloud Computing & MSA ]
조회수: 22719

참고

https://www.redhat.com/sysadmin/podman-windows-wsl2

Podman 설치

$ vim get-podman.sh
#!/bin/sh
. /etc/os-release
sudo sh -c "echo 'deb <http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/x${NAME}_${VERSION_ID}/> /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
wget -nv <https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/x${NAME}_${VERSION_ID}/Release.key> -O Release.key
sudo apt-key add - < Release.key
sudo apt-get update -qq
sudo apt-get -qq -y install podman
sudo mkdir -p /etc/containers
echo -e "[registries.search]\\nregistries = ['docker.io', 'quay.io']" | sudo tee /etc/containers/registries.conf

$ chmod +x get-podman.sh
$ ./get-podman.sh

WSL을 위한 설정 변경

ubuntu 패키지의 기본 값으로 cgroup manager는 systemd, events logger는 journald로 설정되어 있기 때문에 아래 값을 변경하지 않으면 실행 시 마다 —cgroup-manager cgroupfs —event_logger file 옵션을 줘야 한다.

$ sudo vim /usr/share/containers/containers.conf
......
cgroup_manager = "cgroupfs"
......
events_logger = "file"

# 현재 계정에서만 사용할 경우(rootless)
$ sudo cp /usr/share/containers/containers.conf ~/.config/containers

# root에서도 podman을 사용할 경우 (rootfull)
$ sudo cp /usr/share/containers/containers.conf /etc/containers

Podman 실행

podman이 정상적으로 올라왔는지 확인한다. 변경한 설정값이 적용되어있음을 확인할 수 있다. 

$ podman info
host:
  arch: amd64
  buildahVersion: 1.18.0
  cgroupManager: cgroupfs
  cgroupVersion: v1
  conmon:
    package: 'conmon: /usr/libexec/podman/conmon'
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.0.22, commit: '
  cpus: 8
  distribution:
    distribution: ubuntu
    version: "20.04"
  eventLogger: file
......

nginx 컨테이너 생성

Podman 네트워크를 생성하고 nginx를 실행시킨다. docker와 기본적으로 동일한 명령어를 사용할 수 있으며, docker로 빌드된 이미지를 사용할 수 있다. 위에서 지정한 docker.io 저장소의 nginx:alpine이미지를 pull 하는 것을 확인할 수 있다.

$ podman network create
/home/ubuntu/.config/cni/net.d/cni-podman0.conflist

$ podman network ls
NAME         VERSION  PLUGINS
cni-podman0  0.4.0    bridge,portmap,firewall,tuning,dnsname

# 컨테이너를 백그라운드에서 실행하며 컨테이너 포트로 포트포워딩
$ podman run -dti -P --name nginx nginx:alpine
Completed short name "nginx" with unqualified-search registries (origin: /etc/containers/registries.conf)
Trying to pull docker.io/library/nginx:alpine...
Getting image source signatures
Copying blob 7453d3e6b909 done
Copying blob e295e0624aa3 done
Copying blob 801bfaa63ef2 done
Copying blob b1242e25d284 done
Copying blob 07ce7418c4f8 done
Copying config 629df02b47 done
Writing manifest to image destination
Storing signatures
3f199a02fb470673dee98519b930d014b4f2c1be4f53509e932fcd21d68e560d

$ podman ps -a
CONTAINER ID  IMAGE       COMMAND       CREATED STATUS            PORTS        NAMES
3f199a02fb47  docker.io/library/nginx:alpine  nginx -g daemon o...  5 seconds ago  Up 5 seconds ago  0.0.0.0:37553->80/tcp  nginx

$ podman port -l
80/tcp -> 0.0.0.0:37553

$ curl localhost:37553
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
......

nginx가 정상적으로 기동됨을 확인할 수 있다.