Docker Compose在Mac上 - 图像位置

时间:2018-04-30 11:49:13

标签: macos docker docker-compose docker-image

我在我的Mac上使用docker-compose进行本地开发。我有多个使用docker compose构建的图像。我的docker和docker-compose设置非常标准。现在我想与某人分享我本地构建的图像文件。这些本地文件存储在哪里?

搜索了一下,给了我一些答案:

~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

但是,如何从中提取一张图像并分享呢?我尝试运行它中存在的tty,但无济于事。

Docker版本:适用于Mac的18.03 Docker

Docker撰写版本:2

2 个答案:

答案 0 :(得分:2)

如果您拥有docker-hub帐户(免费),则可以使用docker push命令将docker镜像保存到注册表中,并使用docker pull拉取其他计算机。

另一种解决方案是使用 save + import 命令。

为此,您可以使用docker savedocker import命令。

docker@default:~$ docker save --help

Usage:  docker save [OPTIONS] IMAGE [IMAGE...]

Save one or more images to a tar archive (streamed to STDOUT by default)

Options:
  -o, --output string   Write to a file, instead of STDOUT
docker@default:~$

之后你的文件系统上有TAR文件(检查-o值)然后将文件传输到另一台机器并执行docker import

docker@default:~$ docker import --help

Usage:  docker import [OPTIONS] file|URL|- [REPOSITORY[:TAG]]

Import the contents from a tarball to create a filesystem image

Options:
  -c, --change list      Apply Dockerfile instruction to the created image
  -m, --message string   Set commit message for imported image
docker@default:~$

答案 1 :(得分:2)

显然,docker-compose的解决方案正在使用docker save命令。我们不需要知道@ fly2matrix提到的图像位置。我们可以使用docker save命令将图像保存在TAR文件中。

docker save --output image-name.tar image-name:tag

然后,其他用户可以通过以下方式共享和加载此图片:

docker load --input image-name.tar