如何保存Docker容器状态 [英] How to save a Docker container state

查看:718
本文介绍了如何保存Docker容器状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试了解Docker的来龙去脉,并且我对保存映像的前景感到困惑。

I'm trying to learn the ins and outs of Docker, and I'm confused by the prospect of saving an image.

我运行了基本的Ubuntu映像,安装了Anaconda Python和其他一些东西...那么,现在保存我的进度的最佳方法是什么?保存,提交,导出?

I ran the basic Ubuntu image, installed Anaconda Python and a few other things...so now what's the best way to save my progress? Save, commit, export?

这些功能似乎都不与VirtualBox相同,后者为您的虚拟机提供了明显的保存状态文件。

None of these seem to work the same way as VirtualBox, which presents an obvious save-state file for your virtual machine.

推荐答案

通常的方法至少是通过 docker commit :这会将容器的状态冻结到一个新映像中。

The usual way is at least through a docker commit: that will freeze the state of your container into a new image.

注意:如anchovylegend ,这不是最佳做法,使用Dockerfile可以使您对图像内容进行正式建模,并确保可以重建/复制其初始内容状态。

Note: As commented by anchovylegend, this is not the best practice, and using a Dockerfile allows you to formally modeling the image content and ensure you can rebuild/reproduce its initial state.

然后您可以使用 docker图片 ,并再次运行它。

You can then list that image locally with docker images, and run it again.

示例:

$ docker ps

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS              NAMES
c3f279d17e0a        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            desperate_dubinsky
197387f1b436        ubuntu:12.04        /bin/bash           7 days ago          Up 25 hours                            focused_hamilton

$ docker commit c3f279d17e0a  svendowideit/testimage:version3

f5283438590d

$ docker images

REPOSITORY                        TAG                 ID                  CREATED             SIZE
svendowideit/testimage            version3            f5283438590d        16 seconds ago      335.7 MB






之后,如果已部署,则注册表服务器,则可以将映像推送到该服务器。


After that, if you have deployed a registry server, you can push your image to said server.

这篇关于如何保存Docker容器状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆