Skip to main content

Buildah and Skopeo


설치

sudo pacman -S buildah skopeo
/etc/containers/registries.conf
unqualified-search-registries = ['docker.io', 'quay.io', 'registry.fedoraproject.org']

Build

<project>
├── Dockerfile
├── containerize.sh
├── go.mod
├── go.sum
└── main.go
main.go
package main

import (
"github.com/gin-gonic/gin"
)

func main() {
r := gin.Default()
r.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
r.Run() // listen and serve on 0.0.0.0:8080 (for windows "localhost:8080")
}

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

Dockerfile

FROM golang:1.17 AS build
COPY . /app
WORKDIR /app
RUN go mod tidy
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -ldflags '-s' -o app

FROM scratch AS runtime
WORKDIR /app
COPY --from=build /app/app /usr/bin/
CMD ["app"]
buildah bud --tag ping .
  • --file <path|url>: Dockerfile의 경로를 설정할 수 있습니다.

Clean

buildah containers
buildah rm <container>
  • --all: 모든 컨테이너를 삭제합니다.
buildah images
buildah rmi <image>
  • --all: 모든 이미지를 삭제합니다.
  • --prune: 댕글링 이미지들을 삭제합니다.

login

skopeo login <url>

ECR

aws ecr get-login-password | skopeo login --username AWS --password-stdin <account>.dkr.ecr.<region>.amazonaws.com
aws ecr-public get-login-password --region us-east-1 | skopeo login --username AWS --password-stdin public.ecr.aws/<alias>

copy

skopeo copy <src-image> <dst-image>
  • image
    • containers-storage:localhost/<image>[:tag]
    • docker://<url>/<image>[:tag]

inspect

skopeo inspect <image>

Reference