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

Viewed 33841

Here is my problem:

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.

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.

Any ideas?

Regards and thanks.

4 Answers

To create a image from container execute the command below:

docker commit container_id imagename

This can be easily done by using "docker commit".

Let's say you need an image, based on the latest from NGINX, with PHP, build-essential, and nano installed. I'll walk you through the process of pulling the image, running the container, accessing the container, adding the software, and committing the changes to a new image that can then be easily used as a base for your dev containers.

Pulling the image and running the container:

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

Modifying the container:

apt-get install nano
​apt-get install php5

Commit the changes:

sudo docker commit CONTAINER_ID nginx-template

The newly created template is ready and you can run using:

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