gpt4 book ai didi

docker - 共享Docker容器

转载 作者:行者123 更新时间:2023-12-02 20:49:20 27 4
gpt4 key购买 nike

我有多个通过文件系统更新修改的Docker容器。这些更新未通过更改dockerFile来表示

这是process的伪代码:

docker pull image
docker run image
docker exec -it <image_id> bash
'make changes to running docker container image
exit running docker container
docker commit <new container name>

要保存容器,我可以使用 docker save...并保存容器的本地副本。可以将其推送到注册表吗?还是注册表仅用于图像而不是容器?

共享自定义docker容器以将其导出为.tar文件然后在其他计算机上重新导入的单一方法是吗?

最佳答案

您从不共享容器,而总是共享图像。您已经使用过docker commit命令未保存容器,而是从该容器的文件系统(documentation)创建新图像:

Create a new image from a container’s changes

Usage

docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]]


您可以像其他任何图像一样对待由docker commit创建的图像(从中创建新容器,将其推送到注册表等)。
只需提交一个现有容器即可创建一个新镜像,然后可以将该镜像推送到所需的任何位置:
$ docker commit <some-running-container> yourusername/new-image
$ docker push yourusername/new-image

如果不想使用注册表,请使用docker save命令将现有图像导出到文件中,然后使用docker load命令再次导入图像。
$ docker commit <some-running-container> yourusername/new-image
$ docker save yourusername/new-image > new-image.tar
$ # On another machine:
$ docker load < new-image.tar

关于docker - 共享Docker容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43829531/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com