이제 docker-compose.yml 같은 파일에 대하여 설명해주는 거같다.
빌드할 dockerfile 이나 어떠한 명령어를 추가하는지 적는 파일이다.
많은 dockerfile을 한번에 만들어주려면 yml, yaml, json, hcl, override.json, override.hcl 과 같은 파일을 만들어 정의해주어야 한다
args | Map | 빌드 시간설정 |
attest | List | 빌드시 인증서 라는데 SBOM 같은 인증서에 대하여 다음장에 배운다 |
cache-from | List | 케시소스를 전달한다 https://fe-developers.kakaoent.com/2022/220414-docker-cache/ |
cache-to | List | 캐시 내보내는 대상 https://docs.docker.com/build/ci/github-actions/cache/ |
context | String | 파일이나 인터넷 주소를 지정한다 |
contexts | Map | 뭔가 옵션으로 많은걸 할 수 있나보다 https://docs.docker.com/engine/reference/commandline/buildx_build/#build-context |
dockerfile-inline | String | 음.. 예시를 찾긴했는데 도커파일 명령어를 넣어주는거 같다 https://matsuand.github.io/docs.docker.jp.onthefly/engine/reference/commandline/buildx_bake/ |
dockerfile | String | 도커파일 지정해 주기 |
inherits | List | hcl 파일만 되는지 아직 모르겟다 하지만 동일한 타겟의 이미지를 만들때 dockerfile들을 병합하여 만들어주는거 같다. Inherit build options |
labels | Map | 이미지에 대한 정보를 적는거인데 (same as --label flag) https://github.com/osbuild/containers/blob/main/docker-bake.hcl 예시를 보는게 좋을거같다 |
no-cache-filter | List | 특정 cache 안사용하는거?? 라하는데 https://github.com/docker/build-push-action/commit/1cb9d22b932e4832bb29793b7777ec860fc1cde0 사용법을 모르겟음.. |
no-cache | Bool | cache들을 다 사용하지 않는 것이다 |
output | List | 출력을 결정한다 (same as --output flag) https://docs.docker.com/engine/reference/commandline/buildx_build/#output 이부분을 보면 어떤 방식인지 이해할 수 있긴함 |
platforms | List | platforms 을 결정하는거다 어떤 컴파일러를 쓸지? (same as --platform flag) |
pull | Bool | 깃처럼 가져와서 쓸 수 있는거인데 내가 만든것도 되고 공개된 이미지도 되는듯? (same as --pull flag) https://docs.docker.com/engine/reference/commandline/pull/ |
secret | List | 아직 모르겟다.. 음.. Secret to expose to the build (same as --secret flag) https://docs.docker.com/engine/reference/commandline/secret/ |
ssh | List | 빌드에 쓸 ssh 를 리스트화 하는거 같음.. (same as --ssh flag) |
tags | List | 이름 정해주는거 근데 왜 이게 List일까.. name:tag (same as --tag flag) |
target | String | targets 로 뭔가 존속성을 만들어 이어주는 느낌? (same as --target flag) |
음 신기하네 hcl 파일은 함수나 변수 같은것도 쓸수있음
# docker-bake.hcl
function "increment" {
params = [number]
result = number + 1
}
group "default" {
targets = ["webapp"]
}
target "webapp" {
args = {
buildno = "${increment(123)}"
}
}
docker buildx bake --print webapp
{
"group": {
"default": {
"targets": [
"webapp"
]
}
},
"target": {
"webapp": {
"context": ".",
"dockerfile": "Dockerfile",
"args": {
"buildno": "124"
}
}
}
}
음!!신기해
다음!
# syntax=docker/dockerfile:1
FROM scratch AS src
FROM golang
COPY --from=src . .
이부분의 --from을 잘 이해가 되지 않는다
docker build -t test .
docker run -it test
이러면
root@624ed67b3d7d:/go# ls
bin src
src 가 있는데 안에는 암것도 없다
음.....왤까? 폴더만 만들어준건가? 안에 내용물이 암것도 들가지않음 신기하네 --from
# docker-compose.yml
services:
webapp-dev:
build: &build-dev
dockerfile: Dockerfile.webapp
tags:
- docker.io/username/webapp:latest
cache_from:
- docker.io/username/webapp:cache
cache_to:
- docker.io/username/webapp:cache
webapp-release:
build:
<<: *build-dev
x-bake:
platforms:
- linux/amd64
- linux/arm64
db:
image: docker.io/username/db
build:
dockerfile: Dockerfile.db
docker buildx bake --print
[+] Building 0.0s (0/0)
{
"group": {
"default": {
"targets": [
"webapp-dev",
"webapp-release",
"db"
]
}
},
"target": {
"db": {
"context": ".",
"dockerfile": "Dockerfile.db",
"tags": [
"docker.io/username/db"
]
},
"webapp-dev": {
"context": ".",
"dockerfile": "Dockerfile.webapp",
"tags": [
"docker.io/username/webapp:latest"
],
"cache-from": [
"docker.io/username/webapp:cache"
],
"cache-to": [
"docker.io/username/webapp:cache"
]
},
"webapp-release": {
"context": ".",
"dockerfile": "Dockerfile.webapp",
"tags": [
"docker.io/username/webapp:latest"
],
"cache-from": [
"docker.io/username/webapp:cache"
],
"cache-to": [
"docker.io/username/webapp:cache"
],
"platforms": [
"linux/amd64",
"linux/arm64"
]
}
}
}
이걸 보고 드디어 잘 이해가 됫다 bake 은 실행 하는거 보는거다 즉 설계도결과를 잘 볼 수 있게 해준다
그리고 그 결과를 보고 다시 설계(docker-compose file 을 뭘 수정해야 하는지 알게됨)!
음 음!!
'42Seoul > Docker' 카테고리의 다른 글
32. docker 메뉴얼 파해치기 Build buildKit (0) | 2023.04.01 |
---|---|
31. docker 메뉴얼 파해치기 Build Attestations (0) | 2023.03.31 |
29. docker 메뉴얼 파해치기 Build cache (0) | 2023.03.31 |
28. docker 메뉴얼 파해치기 Build exporter (0) | 2023.03.24 |
27. docker 메뉴얼 파해치기 Build Drivers (1) | 2023.03.24 |