Docker: Builds, multi-platform & moving images
11 Docker commands: Builds, multi-platform & moving images. Click a command to see what each part does.
Docker: Builds, multi-platform & moving imagesIndex
- Whole sheet120
- Basics: images & containers11
- Volumes & networks4
- Find & inspect containers7
- Environment variables & container config12
- Software versions inside containers & images9
- Logs & shells5
- Run containers3
- Images4
- Cleanup6
- Docker Compose v27
- Container lifecycle & live changes10
- Builds, multi-platform & moving images11
- Volumes, networks & remote hosts in depth12
- Compose: more commands9
- Swarm mode10
Builds, multi-platform & moving images11
docker build --build-arg <ARG>=<value> --target <stage> --no-cache -t <image>:<tag> .Build with build args, a target stage and no cacheWhat each part does
--build-arg <ARG>=<value>set an ARG declared in the Dockerfile (not for secrets: they stay in history)--target <stage>stop at this stage of a multi-stage build--no-cacherebuild every layer-t <image>:<tag>name the result.build context
docker build -f <path>/Dockerfile.prod -t <image>:<tag> .Use a different DockerfileWhat each part does
-f <path>/Dockerfile.prodDockerfile to use.build context (can differ from the Dockerfile's folder)
docker build --secret id=npmrc,src=$HOME/.npmrc -t <image>:<tag> .Pass a secret to a build without leaving it in the imageWhat each part does
--secret id=npmrc,src=...mount a file only during the RUN step that asks for itDockerfile sideRUN --mount=type=secret,id=npmrc,target=/root/.npmrc npm ci
docker buildx build --platform linux/amd64,linux/arm64 -t <registry>/<image>:<tag> --push .Build for several CPU architectures and pushWhat each part does
docker buildx buildBuildKit builder with multi-platform support--platform linux/amd64,linux/arm64build both (Intel/AMD servers and ARM like Graviton or Apple Silicon)--pushpush the multi-arch image straight to the registry
docker buildx ls; docker buildx create --name <builder> --useList and create buildx buildersWhat each part does
docker buildx lsbuilders and the platforms they supportdocker buildx create --usenew builder (docker-container driver) and make it the default
docker build --progress=plain -t <image>:<tag> .Build with plain progress output (CI logs)What each part does
--progress=plainfull, line-by-line output of every step instead of the collapsing TTY view
docker save -o <file>.tar <image>:<tag>Save an image to a file (no registry)What each part does
docker saveexport one or more images with all layers and tags-o <file>.tarwrite to a tar file
docker load -i <file>.tarLoad an image from a fileWhat each part does
docker loadimport images saved with docker save-i <file>.tarinput file (also reads .tar.gz)
docker save <image>:<tag> | gzip | ssh <user>@<host> 'gunzip | docker load'Copy an image to another host over SSHWhat each part does
docker save <image>:<tag>stream the image as tar| gzipcompress it| ssh <user>@<host> '...'send it to the other machinegunzip | docker loadunpack and load it there
docker export <container> -o <file>.tarExport a container's filesystemWhat each part does
docker exportflatten the container's filesystem into a tar (no layers, history or metadata)-o <file>.taroutput file
docker initGenerate a Dockerfile, compose file and .dockerignoreWhat each part does
docker initasks about your project (Node, Python, Go...) and writes starter Docker files
Nothing matches.
My DevOps Playbook by Angelo John Calleja