I have a docker container already running. I have made some configuration changes, let's say have added some host info in /etc/hosts inside the container. How do I keep the changes saved, so that next time when I open an interactive shell to the container I don't have to do the same stuff again ? For now I have created a mini script as addhosts.sh as below inside the container and have to run it every time.
echo "18.104.22.168 server1.example.com gluster1" >> /etc/hosts
echo "22.214.171.124 server2.example.com gluster2" >> /etc/hosts
You can commit the changes you made by:
Short Command reference:
docker commit <container id or name> <repository name>/<your image name>:<tage aka version>
docker commit c3f279d17e0a svendowideit/testimage:version3
Usage: docker commit [OPTIONS] CONTAINER [REPOSITORY[:TAG]] Create a new image from a container's changes Options: -a, --author string Author (e.g., "John Hannibal Smith <email@example.com>") -c, --change value Apply Dockerfile instruction to the created image (default ) --help Print usage -m, --message string Commit message -p, --pause Pause container during commit (default true)
Then you can use
docker images to view your new Image after commit.
To run a container from your new Image:
docker run -d svendowideit/testimage:version3 <optional startup command>
Another way would be creating your own image via:
dockerfile, I'm Just putting it here just incase we can help others.