Mac下Docker Compose本地构建镜像的存储位置及提取分享问询
Hey there, let's skip messing around with that Docker.qcow2 file directly—it's the virtual disk image for Docker Desktop's underlying Linux VM, and digging into it is way more complicated than necessary. Docker has built-in tools to handle exporting and sharing individual images cleanly, which is the standard approach here.
Here's a step-by-step breakdown to get your image ready for sharing:
First, identify your target image
Run this command to list all local Docker images:docker imagesIf you built images via Docker Compose, you can also use this command to filter only Compose-related images (it'll show you the image names tied to your Compose services):
docker-compose imagesNote down either the full image name + tag (like
my-dev-project_web:latest) or the image ID (the long hex string) for the image you want to share.Export the image to a portable tar file
Use thedocker savecommand to package the image into a tar archive. Replace<output-file.tar>with your desired filename, and<image-reference>with either the name:tag or image ID you noted:docker save -o <output-file.tar> <image-reference>Example:
docker save -o my-web-service.tar my-dev-project_web:latestThis tar file will include all the image layers and metadata needed to recreate the image on another machine.
Share and import the image
Send the tar file to whoever needs it, and they can import it into their Docker environment with:docker load -i <output-file.tar>
Why you shouldn't touch Docker.qcow2
That virtual disk file contains the entire filesystem of Docker Desktop's Linux backend, including all images, containers, and system files. Extracting an image from it would require:
- Accessing the Docker VM's shell (which you tried and had trouble with)
- Locating the image storage directory (
/var/lib/docker/images) inside the VM - Manually packing the image layers into a tar without breaking dependencies
It's error-prone, risky (you could corrupt your Docker setup), and completely unnecessary when docker save does all this work for you.
If you're curious about accessing the Docker VM anyway (for learning, not for this task), you can run this command to get a shell into it:
docker run -it --privileged --pid=host debian nsenter -t 1 -m -u -i -n sh
But again, stick to docker save for exporting images—it's the right tool for the job.
内容的提问来源于stack exchange,提问作者Sid

