How to create a docker image from running or existing docker container ….

Anuradh
1 min readSep 6, 2018

Think that you have a running docker container and you have done some changes to it with bash into it or , you want to change published port of the running docker container ….

What you have to do is :

step 01 : stop your running container with (if it is already stopped continue)

docker container stop 'your_container_id/your_container_name ,

then when you list your all containers(running and stopped) with docker container ls -a then it should list there with it’s status is Exited.

step 02 : do a docker commit which creates a new docker image of your stopped container with below command

docker commit 'stoped_container_id/name' 'new_image_name'

it will create a new image with the same configurations as your stopped container. now if you list down the images with docker image ls now you can see a new image in your docker image list.

step 03: then create your new container with

docker container run --name 'my_new_container' --publish aaaa:bbbb -d 'image_name_created_in_previous_step' .

this will create a new container for you.

Thank you and cheers !

--

--