Committing an interactive container in docker

I am trying to install the vim editor on bash in the centOS container in docker. However, as soon as I am exiting the container, I am losing my progress. Is there a way where I can commit the container after I am done with downloading the editor?
This is what I am doing:

user@personal-pc:~/Desktop$ sudo docker run -i -t centos /bin/bash
[root@9c0f428c4907 /]# yum install vim

After the installation is done, the editor works perfectly. However, when I end this running session, and run bash again, then the editor does not exist.

  • Run docker and keep zshhistory from host (zsh shell) in docker container (bash shell)
  • How to get local host IP address in docker container?
  • Daemon started with “docker run daemon” is not working
  • How to run bash function in Dockerfile
  • bash: child setpgid (5870 to 5870): No such process on docker
  • AWS Configure Bash One Liner
  • [root@d17ae0e8bf85 /]# vim abc.txt
    bash: vim: command not found

    How do I go about committing the previous container where the editor was installed?

  • docker build fails on a cloud VM
  • Saving function output into a variable named in an argument
  • Starting oracle with docker: “TNS:listener: all appropriate instances are blocking new connections” error
  • I am able to fetch the URL from Rancher Stack using Putty. How do I fetch the same URL from a Rancher Stack using shell commands in Jenkins
  • Apache2 Container on BlueMix won't stay up
  • How to program with docker? [closed]
  • 2 Solutions collect form web for “Committing an interactive container in docker”

    when I end this running session
    -> so now, you do docker commit 1234 mycontainer , if you start a new interactive session, you lose what you did before

    commit the container 9c0f428c4907 with a new name.(After installing vim)
    Eg: docker commit 9c0f428c4907 centos_viminstalled

    Now run this cnetos_viminstalled image in a container
    docker run -i -t cnetos_viminstalled /bin/bash
    You will be able to see that vim is installed in this new image centos_viminstalled

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.