My Docker Version - 19.03.8, build afacb8b
I have pulled the ubuntu:18.04
from DockerHub
. Then followed the below steps to add two new lines into /etc/hosts
file of my docker image.
docker images
docker run --name ubuntu-18-1 -idt 8b353a2e5d1b /bin/bash
docker ps
# Executed the Container
docker exec -it 985ae774a352 /bin/bash
root@985ae774a352:/# cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 985ae774a352
After adding the following two new lines (56.57.58.59 example1.com
& 56.57.58.60 example2.com
) into /etc/hosts
file of my container, Then after i have saved, exited and then finally i have committed my container.
docker commit 985ae774a352 ubuntu-18-2
# Even after commit i can able to view the changes i made.
docker exec 985ae774a352 cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 985ae774a352
56.57.58.59 example1.com
56.57.58.60 example2.com
# Stopped & Removed the Container
docker container stop 985ae774a352
docker container rm 985ae774a352
# Launched the Container with udpated Image:-
docker run --name ubuntu-18-2 -idt 0ebc2d94a384 /bin/bash
docker ps
docker exec a8c1fa1dd65f cat /etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.2 a8c1fa1dd65f
So in new image i can't see my changes that i made in /etc/hosts
file. Please correct me if something wrong in above followed steps.