Monday, August 6, 2018

Update a running docker container and create a new image


Sometimes during development, you may want to update few files inside docker container - and wish to create a new image out of it.

You can make use of docker commit.

first get the docker id of the images you wish to save. using docker ps

# docker ps

02738dcd4cc2


Then, make changes inside the docker container (02738dcd4cc2) .

For example,

docker exec -it 02738dcd4cc2 bash
# touch /root/testfile 
# edit some configuration


Now, exit the docker container (02738dcd4cc2) and save a new image.
# docker commit 02738dcd4cc2 <updated_docker_container_name_you_have_given>


Now, you can run this  <updated_docker_container_name_you_have_given>, to see the changes.


Use this option judiciously.

Ideally, you should always make use of Dockerfile to make changes and test :)

No comments:

Post a Comment