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

Anuradh
Anuradh
Sep 6, 2018 · 1 min read

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 !

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade