如何创建Ubuntu(运行)基础映像以在其他环境中进行复制。

时间:2017-02-08 20:13:01

标签: docker

我有两个问题,关于如何从运行的Ubuntu和Working项目目录构建docker镜像到基础图像版本

1)如何从运行的Ubuntu(14.0.4)创建基本映像。它具有MongoDB和其他必需的依赖关系来支持我们的应用程序。

2)基于Previous image,想要为应用程序(项目目录)创建基本映像,以便为部署创建版本zed映像。

提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以将容器转换为docker commit的图像:

# start a new ubuntu container, change some things and stop it again
$ docker run -it ubuntu
root@ca93ddb728ae:/# echo "changed image" > file
root@ca93ddb728ae:/# cat /file 
changed image
root@ca93ddb728ae:/# exit
exit

# the container still exists but it's stopped now
# turn it's current state into an image called 'my-ubuntu-image'
$ docker commit ca93ddb728ae my-ubuntu-image
sha256:47b71ccc78ae0b54598f153b1c999c01a9039b654e90da3a3ef3514b2f987df0

# start a container of our new 'my-ubunut-image' and find the previously
# changed file
$ docker run -it my-ubuntu-image
root@2732f428bf8a:/# cat /file 
changed image

之后,您可以像以前一样使用新图像构建新图像。但是,建议使用Dockerfile来创建图像。