Podman 사용 가이드
정보
Podman 개요 문서와 설치 및 환경 설정 문서를 먼저 확인할 수 있습니다.
이미지 빌드
Dockerfile
buildah bud [<flags>] [<context>]
- flags
-f|--file <path|url>: Dockerfile 경로-t|--tag <tag>
ShellScript
containerize.sh
#!/usr/bin/env bash
set -x
build=$(buildah from golang:1.17)
build_root=$(buildah mount $build)
buildah copy $build . /app
buildah config --workingdir /app $build
buildah run $build go get -u github.com/gin-gonic/gin
buildah run $build env CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s' -o app
runtime=$(buildah from scratch)
buildah copy $runtime $build_root/app/app /usr/bin/
buildah config --cmd "app" $runtime
buildah commit $runtime ping:1.0.0
buildah rm $runtime
buildah unmount $build_root
buildah rm $build
buildah unshare sh containerize.sh
이미지 관리
레지스트리에 로그인
skopeo login [<flags>] <host>
aws ecr get-login-password --region <region> | skopeo login --username AWS --password-stdin <awsAccountID>.dkr.ecr.<region>.amazonaws.com
aws ecr-public get-login-password --region <region> | skopeo login --username AWS --password-stdin public.ecr.aws/<alias>
이미지 삭제
podman image rm [<flags>] [<image> ...]
-a|--all-f|--force
이미지 옮기기
skopeo copy [<flags>] <srcImage> <dstImage>
- flags
--dest-creds=<username>:<password>--dest-tls-verify=treu
- image
containers-storage:localhost/<image>[:tag]docker://<url>/<image>[:tag]
inspect
skopeo inspect [<flags>] <image>
파일로 저장하고 불러오기
podman save -o <file>.tar <image>
podman load -i <file>.tar
컨테이너 관리
컨테이너 실행하기
podman run [<flags>] <image> [<command> [<arg> ...]]
새로운 컨테이너에 명령어를 실행합니다.
<flags>--cpus <number>: CPU limit-d|--detach: 컨테이너를 백그라운드에서 실행하고 컨테이너 ID를 출력합니다.--entrypoint <command>|'["<command>", "<arg>", ..."]': Dockerfile의ENTRYPOINT에 해당합니다.--env-file <path>:.env처럼 환경 변수 값이 있는 파일로 환경 변수를 설정합니다.-e|--env <key>[=<value>]: 환경 변수를 설정합니다.<key>만 있는 경우 호스트에서 해당 환경 변수를 찾아 설정하고 없으면 설정하지 않습니다.*glob를 사용할 수 있습니다.
-it: STDIN을 열고 컨테이너에 가상 터미널을 할당합니다.-m|--memory <number><unit>: 메모리 limit<unit>:b,k,m,g
--name <containerName>: 컨테이너 이름--network "host": 호스트 네트워크 사용-p|--publish <hostPort>:<containerPort>[/<protocol>]: 포트 포워딩--rm: 종료 시 컨테이너 삭제-v|--volume <hostDir>:<containerDir>[:<options>]: 호스트 디렉터리를 컨테이너 디렉터리에 마운트합니다.<options>ro: 읽기 전용rw: 읽기 쓰기z: 공유 볼륨으로 설정하여 모든 컨테이너가 읽고 쓸 수 있습니다.
[<command> [<arg> ...]]- Dockerfile의
CMD에 해당합니다.
- Dockerfile의
컨테이너 리스트
podman ps [<flags>]
-a|--all: 모든 컨테이너 출력-l|--latest: 마지막 컨테이너 출력-q|--quiet: 컨테이너 ID만 출력
실행 중 컨테이너에 명령어 실행
podman exec [<flags>] <container> <command> [arg ...]
실행 중인 컨테이너에 명령어를 실행합니다.
- flags
-it: STDIN을 열고 컨테이너에 가상 터미널 할당
- container
- container ID 또는 이름