如何从Amazon上正在运行的容器中创建新的Docker映像? [英] How to create a new docker image from a running container on Amazon?

查看:132
本文介绍了如何从Amazon上正在运行的容器中创建新的Docker映像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题:

我有一个任务在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 image,可以从Amazon中提取它.

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守护程序端口,并且在此处说明该过程

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 Image运行容器并在容器内创建一个文件夹:

#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是通过提交容器而构建的新图像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

运行新构建的映像,以查看在先前容器中提交的更改.

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的更多信息,请参考 查看全文

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