From e56cde6b3136761a0e9145aee53bce550e957b9a Mon Sep 17 00:00:00 2001 From: Michele Cereda Date: Wed, 10 Apr 2024 18:18:57 +0200 Subject: [PATCH] chore(kb/docker): improve tl;dr --- .vscode/settings.json | 1 + knowledge base/docker.md | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a34609..32279fb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -75,6 +75,7 @@ "bootloader", "bssid", "btrfs", + "buildkit", "burstable", "byod", "celeron", diff --git a/knowledge base/docker.md b/knowledge base/docker.md index 1192311..334ac43 100644 --- a/knowledge base/docker.md +++ b/knowledge base/docker.md @@ -3,6 +3,7 @@ 1. [TL;DR](#tldr) 1. [Gotchas](#gotchas) 1. [Daemon configuration](#daemon-configuration) +1. [Images configuration](#images-configuration) 1. [Containers configuration](#containers-configuration) 1. [Advanced build with `buildx`](#advanced-build-with-buildx) 1. [Create builders](#create-builders) @@ -12,12 +13,21 @@ ## TL;DR +
+ Installation and configuration + ```sh # Install brew install --cask 'docker' sudo zypper install 'docker' +``` +
+
+ Usage + +```sh # Show locally available images. docker images -a @@ -27,9 +37,13 @@ docker search 'boinc' # Pull images. docker pull 'alpine:3.14' docker pull 'boinc/client:latest' +docker pull 'moby/buildkit@sha256:00d2…' +docker pull 'pulumi/pulumi-nodejs:3.112.0@sha256:37a0…' -# Get the SHAsum of images. -docker inspect --format='{{index .RepoDigests 0}}' 'node:18-buster' +# Remove images. +docker rmi 'node' +docker rmi 'alpine:3.14' +docker rmi 'f91a431c5276' # Login to registries. docker login @@ -79,12 +93,14 @@ docker top 'alpine-test' # Show information on containers. docker inspect 'alpine-test' +docker inspect --format='{{index .RepoDigests 0}}' 'pulumi/pulumi-nodejs:3.112.0' # Build a docker image. docker build -t 'private/alpine:3.14' . # Tag images. docker tag 'alpine:3.14' 'private/alpine:3.14' +docker tag 'f91a431c5276' 'pulumi/pulumi-nodejs:3.112.0' # Push images. docker push 'private/alpine:3.14' @@ -142,6 +158,7 @@ docker buildx create --node 'builder_name' # Build images. # '--load' currently only works for builds for a single platform. docker buildx build -t 'image:tag' --load '.' +docker buildx build … -t 'image:tag' --load --platform 'linux/amd64' '.' docker buildx build … --push \ --platform 'linux/amd64,linux/arm64,linux/arm/v7' '.' @@ -167,6 +184,18 @@ docker compose logs -f --index='3' 'service-name' docker compose down ``` +
+ +
+ Real world use cases + +```sh +# Get the SHAsum of images. +docker inspect --format='{{index .RepoDigests 0}}' 'node:18-buster' +``` + +
+ ## Gotchas - Containers created with no specified name will be assigned one automatically: @@ -216,6 +245,10 @@ The docker daemon is configured using the `/etc/docker/daemon.json` file: } ``` +## Images configuration + +One should follow the [OpenContainers Image Spec]. + ## Containers configuration Docker mounts specific system files in all containers to forward its settings: @@ -277,6 +310,7 @@ docker load … - [Cheatsheet] - [Getting around Docker's host network limitation on Mac] - [Building multi-arch images for ARM and x86 with Docker Desktop] +- [OpenContainers Image Spec]