Docker
Install docker¶
ref: https://docs.docker.com/engine/install/ubuntu/#install-using-the-convenience-script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker rammus
docker-compose: https://docs.docker.com/compose/install/
sudo curl -L "https://github.com/docker/compose/releases/download/1.27.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
Minimize docker image¶
Delete libraries only used in build time¶
apk update \
&& apk add --no-cache --virtual .build-deps curl \
&& curl -sL $TOOL_URL | gzip -d - > /usr/local/bin/new_tool \
&& chmod +x /usr/local/bin/new_tool \
&& apk del .build-deps
Clena docker legacy data¶
docker image prune -af
docker rmi $(docker images -f "dangling=true" -q) -f
docker volume rm $(docker volume ls -qf dangling=true)
Buildkit¶
Troubleshooting¶
{"registry-mirrors": ["https://mirror.gcr.io"]} cause error¶
不能和 registry-mirrors 一起用 (issue: https://github.com/moby/moby/issues/39120)
resolve image config for docker.io/docker/dockerfile:experimental:¶
DOCKER_BUILDKIT=1 docker build -t demo .
[+] Building 0.5s (3/3) FINISHED
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 259B 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> ERROR resolve image config for docker.io/docker/dockerfile:experimental 0.5s
------
> resolve image config for docker.io/docker/dockerfile:experimental:
------
failed to solve with frontend dockerfile.v0: failed to solve with frontend gateway.v0: docker.io/docker/dockerfile:experimental not found
Solution
在 ~/.docker/daemon.json
加入
"features": {
"buildkit": true
}
DOCKER_BUILDKIT=1
要在 Dockerfile 開頭加入 # syntax = docker/dockerfile:experimental
# syntax = docker/dockerfile:experimental
FROM alpine:3.10
failed to solve with frontend dockerfile.v0: failed to create LLB definition: Dockerfile parse error line 3: Unknown flag: mount
error: failed to get status: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /run/buildkit/buildkitd.sock: connect: no such file or directory"¶
error: failed to get status: rpc error: code = Unavailable desc = connection error: desc = "transport: error while dialing: dial unix /run/buildkit/buildkitd.sock: connect: no such file or directory"
buildctl build \
--frontend=dockerfile.v0 \
--local context=echo-box/2.0 --local dockerfile=echo-box/2.0 \
--output type=image,name=ghcr.io/swaglive/action-demo:2.0,push=true \
--export-cache type=inline \
--import-cache type=registry,ref=ghcr.io/swaglive/action-demo:2.0