如何从 Amazon 上正在运行的容器创建新的 docker 镜像? [英] How to create a new docker image from a running container on Amazon?
问题描述
这是我的问题:
我有一项在 Amazon ECS 上运行 Docker 映像的任务,但我想从正在运行的容器实例创建一个新的 Docker 映像.
I have a task running a Docker image on Amazon ECS but I would like to make a new Docker image from the running instance of the container.
我在 Amazon ECS 上看到了实例的 id;我已经制作了一个 AMI,但我想制作一个可以从亚马逊拉取的新 docker 镜像.
I see the id of the instance on Amazon ECS; I have made an AMI but I would like to make a new docker image that I can pull from Amazon.
有什么想法吗?
问候和感谢.
推荐答案
除了@Ben Whaley 提供的答案,我个人建议您使用 Docker API. 要使用 Docker API,您需要配置 docker daemon 端口,这里解释了过程 配置docker daemon端口
Apart from the answer provided by @Ben Whaley, I personally suggest you to make use of Docker APIs. To use Docker APIs you need to configure the docker daemon port and the procedure is explained here configuring docker daemon port
让我们使用基本 Ubuntu 映像运行容器并在容器内创建一个文件夹:
#docker run -it ubuntu:14.04 /bin/bash
root@58246867493d:/#
root@58246867493d:/# cd /root
root@58246867493d:~# ls
root@58246867493d:~# mkdir TEST_DIR
root@58246867493d:~# exit
退出容器的状态:
# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58246867493d ubuntu:14.04 "/bin/bash" 2 minutes ago Exited (127) 57 seconds ago hungry_turing
作为提交容器的输入的 JSON 文件:
JSON file which is an input for committing a container:
#cat container_create.json
{
"AttachStdin": true,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"property1": {},
"property2": {}
},
"Tty": true,
"OpenStdin": true,
"StdinOnce": true,
"Cmd": null,
"Image": "ubuntu:14.04",
"Volumes": {
"additionalProperties": {}
},
"Labels": {
"property1": "string",
"property2": "string"
}
}
用于提交容器的 API
# curl -X POST http://127.0.0.1:6000/commit?container=58246867493d&repo=ubuntu&tag=15.0 -d @container_create.json --header "Content-Type: application/json" | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 593 100 81 100 512 175 1106 --:--:-- --:--:-- --:--:-- 1108
{
"Id": "sha256:acac1f3733b2240b01e335642d2867585e5933b18de2264315f9b07814de113a"
}
生成的 Id 是通过提交容器构建的新 Image Id.
The Id that is generated is the new Image Id which is build from committing a container.
获取 docker 图像
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
**ubuntu 15.0 acac1f3733b2 10 seconds ago 188MB**
ubuntu 14.04 132b7427a3b4 10 hours ago 188MB
运行新构建的 Image 以查看在前一个容器中提交的更改.
Run the newly build Image to see the changes commited in the previous container.
# docker run -it ubuntu:15.0 /bin/bash
root@3a48af5eaec9:/# cd /root/
root@3a48af5eaec9:~# ls
TEST_DIR
root@3a48af5eaec9:~# exit
要从 Docker 文件构建镜像,如何构建镜像使用 docker API
To build an image from Docker file, how to build an image using docker API
有关Docker API 的更多信息,请参阅此处.
这篇关于如何从 Amazon 上正在运行的容器创建新的 docker 镜像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!