How to create a new docker image from a running container on Amazon?

Here is my problem:

I have the task of running docker image on amazon ECS, but I would like to make a new docker image from a running container instance.

I see the instance id on Amazon Ecs, I did AMI, but I would like to make a new docker image that I can extract from Amazon.

Any ideas?

With respect and gratitude

+7
source share
4 answers

In addition to the answer provided by @Ben Whaley, I personally suggest you use the Docker APIs. . To use the Docker APIs, you need to configure the docker daemon port, and the procedure here is to configure the docker daemon port

Allows you to start the container using the base Ubuntu Image and create a folder inside the container :

#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 

Outbound container status:

 # 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 file, which is the input for fixing the 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" } } 

Container commit 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" } 

The identifier that is generated is the new Image Identifier that is created from the container commit.

Get docker images

 # docker images REPOSITORY TAG IMAGE ID CREATED SIZE **ubuntu 15.0 acac1f3733b2 10 seconds ago 188MB** ubuntu 14.04 132b7427a3b4 10 hours ago 188MB 

Start a new imaging to see the changes made to the previous container.

 # docker run -it ubuntu:15.0 /bin/bash root@3a48af5eaec9 :/# cd /root/ root@3a48af5eaec9 :~# ls TEST_DIR root@3a48af5eaec9 :~# exit 

To create an image from a Docker file, how to create an image using the docker API

For more information on docker APIs , here.

+3
source

To create an image from the container, run the following command:

docker commit hw_container hw_image

+16
source

You can run docker commit ( docs ) to save the container in the image, and then click that image using the new tag in the registry.

+4
source

This can easily be done using the "Docker commit".

Let's say you need an image based on the latest version of NGINX, with PHP installed, build-essential and nano. I will guide you through the process of extracting the image, launching the container, accessing the container, adding software and making changes to the new image, which can then be easily used as the basis for your developer containers.

Pull out the image and start the container:

 sudo docker pull nginx sudo docker run -it --name nginx-template-base -p 8080:80 nginx 

Container Change:

 apt-get install nano ​apt-get install php5 

Confirm changes:

 sudo docker commit CONTAINER_ID nginx-template 

The newly created template is ready and you can run it with:

 sudo docker run -it --name nginx-dev -p 8080:80 nginx-template 
0
source

Source: https://habr.com/ru/post/1268686/


All Articles