Prepare a Docker image for offline transfer by tagging it for internal use, exporting it to a tar archive, removing it from the local host, loading it back, and proving it is runnable before cleanup.
Ops ticket: Prepare an image for offline transfer to a restricted environment. Pull a base image, add an internal tag, export it to a tar archive, remove it locally, then load it back and prove it is available and runnable.
This workflow is common when the destination environment has no registry access. Your evidence is the tar archive plus the ability to load and run the image.
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker pull alpine:latest
latest: Pulling from library/alpine
Digest: sha256:........................................................
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest
corp/alpine:transfer
docker tag alpine:latest corp/alpine:transfer
(tag created)
docker images | grep -E "^(alpine|corp/alpine)"
alpine latest 4e38e38c8ce0 2 weeks ago 7.3MB
corp/alpine transfer 4e38e38c8ce0 2 weeks ago 7.3MB
docker save -o /root/alpine-transfer.tar corp/alpine:transfer
(image saved)
docker rmi corp/alpine:transfer alpine:latest
Untagged: corp/alpine:transfer
Untagged: alpine:latest
Deleted: sha256:........................................................
docker images | grep -E "^(alpine|corp/alpine)" || true
(no output)
docker load -i /root/alpine-transfer.tar
Loaded image: corp/alpine:transfer
/etc/os-release).
docker run --rm corp/alpine:transfer cat /etc/os-release
NAME="Alpine Linux"
ID=alpine
VERSION_ID=3.19.1
docker rmi corp/alpine:transfer
Untagged: corp/alpine:transfer
Deleted: sha256:........................................................
rm -f /root/alpine-transfer.tar
(removed)
Multiple tags can reference the same image ID. Remove all tags pointing to the image before expecting the underlying image to be deleted.
docker load restores whatever repository and tag names are in the tar archive. Confirm what was saved before transfer.
Confirm the correct tag is present with docker images and run the exact repository and tag you loaded.
Remove the transferred image tag and the tar archive to prevent disk drift and stale artifacts.
docker images | grep -E "^(alpine|corp/alpine)" || true
docker rmi corp/alpine:transfer || true
rm -f /root/alpine-transfer.tar
docker images shows no alpine or corp/alpine tags,
and the tar file is removed from /root.
docker images
: Lists local images.
docker pull <image>:<tag>
: Downloads an image from a registry.
docker tag <src>:<tag> <dst>:<tag>
: Adds a new tag pointing to an existing image ID.
docker save -o <file.tar> <image>:<tag>
: Exports an image to a tar archive for offline transfer.
-o
: Writes output to a file path.
docker load -i <file.tar>
: Imports an image tar archive into the local image store.
-i
: Reads input from a file path.
docker rmi <image>:<tag>
: Removes an image tag (and deletes the image only when no tags remain).
docker run --rm <image>:<tag> <cmd>
: Runs a container from an image and removes it on exit.
--rm
: Automatically removes the container when it exits.
grep -E <pattern>
: Filters output using an extended regular expression.
-E
: Enables extended regex syntax.
|| true
: Prevents a non-zero exit status from breaking a command chain.
rm -f <path>
: Removes a file without prompting.
-f
: Ignores missing files and suppresses prompts.