Many developers face situations where they need to work with Docker in restricted network environments. While Docker Hub is the standard way to obtain images, it's not always accessible from production or secure development environments.
The Docker CLI provides built-in commands to export and import images as tar archives:
# On your internet-connected machine:
docker pull nginx:latest
docker save -o nginx_image.tar nginx:latest
# On your offline machine:
docker load -i nginx_image.tar
For transferring multiple images at once:
# Saving multiple images
docker save -o my_images.tar nginx:latest redis:alpine postgres:13
# Loading them later
docker load -i my_images.tar
If you have more complex needs, consider setting up a local registry:
# On internet machine
docker pull registry:2
docker run -d -p 5000:5000 --name registry registry:2
docker tag nginx:latest localhost:5000/nginx
docker push localhost:5000/nginx
# Export the registry container
docker export -o registry_container.tar registry
# On offline machine
docker import registry_container.tar
docker run -d -p 5000:5000 --name registry registry:2
docker pull localhost:5000/nginx
Always verify your transferred images:
# Check loaded images
docker images
# Verify image digest matches original
docker inspect --format='{{.RepoDigests}}' nginx:latest
- Compress tar files for faster transfer:
gzip nginx_image.tar
- For very large images, consider splitting the archive
- Maintain a version manifest file with SHAs
- Remember to include all dependent layers
In secured enterprise environments, developers often face this exact scenario: internet-connected workstations with strict installation policies, while development machines operate in air-gapped networks. Docker's architecture actually provides several built-in solutions for this exact workflow.
The most straightforward approach involves these commands:
# On internet-connected machine docker pull nginx:latest docker save -o nginx_image.tar nginx:latest # Transfer the .tar file via USB/CD # On air-gapped machine docker load -i nginx_image.tar
When dealing with different architectures (e.g., downloading on AMD64 but deploying on ARM):
# Pull specific platform image docker pull --platform linux/arm64 nginx:latest # Verify architecture before saving docker inspect nginx:latest | grep Architecture
For transferring entire development environments:
# Save multiple images docker save -o dev_stack.tar nginx:latest postgres:15 redis:7 # Later load all at once docker load -i dev_stack.tar
After transfer, verify integrity and clean up temporary files:
# List transferred images docker images # Remove temporary archive rm nginx_image.tar # On Linux/Mac del nginx_image.tar # On Windows