Skip to content

Docker: Builds, multi-platform & moving images

11 Docker commands: Builds, multi-platform & moving images. Click a command to see what each part does.

Index
11 items
Click a command to see what each part does.

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 cache

    What each part does

    1. --build-arg <ARG>=<value>set an ARG declared in the Dockerfile (not for secrets: they stay in history)
    2. --target <stage>stop at this stage of a multi-stage build
    3. --no-cacherebuild every layer
    4. -t <image>:<tag>name the result
    5. .build context
  • docker build -f <path>/Dockerfile.prod -t <image>:<tag> .Use a different Dockerfile

    What each part does

    1. -f <path>/Dockerfile.prodDockerfile to use
    2. .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 image

    What each part does

    1. --secret id=npmrc,src=...mount a file only during the RUN step that asks for it
    2. Dockerfile 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 push

    What each part does

    1. docker buildx buildBuildKit builder with multi-platform support
    2. --platform linux/amd64,linux/arm64build both (Intel/AMD servers and ARM like Graviton or Apple Silicon)
    3. --pushpush the multi-arch image straight to the registry
  • docker buildx ls; docker buildx create --name <builder> --useList and create buildx builders

    What each part does

    1. docker buildx lsbuilders and the platforms they support
    2. docker 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

    1. --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

    1. docker saveexport one or more images with all layers and tags
    2. -o <file>.tarwrite to a tar file
  • docker load -i <file>.tarLoad an image from a file

    What each part does

    1. docker loadimport images saved with docker save
    2. -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 SSH

    What each part does

    1. docker save <image>:<tag>stream the image as tar
    2. | gzipcompress it
    3. | ssh <user>@<host> '...'send it to the other machine
    4. gunzip | docker loadunpack and load it there
  • docker export <container> -o <file>.tarExport a container's filesystem

    What each part does

    1. docker exportflatten the container's filesystem into a tar (no layers, history or metadata)
    2. -o <file>.taroutput file
  • docker initGenerate a Dockerfile, compose file and .dockerignore

    What each part does

    1. docker initasks about your project (Node, Python, Go...) and writes starter Docker files

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…