Reputation: 1211
Using a blank centos7 image I start a container with docker run -it centos:7.7.1908
I set the hostname at /etc/hostname
and IP with hostname at /etc/hosts
and make a few other changes.
At this point all looks good. I then open up another shell
get the contain ID and do a docker commit, basically make a new image foo
from the running container
When i then start a new container from the image foo docker run -it foo
it has all the changes I made with the exception to the changed in the /etc/hosts
and /etc/hostname
. They get reset to some random sting and IP address.
Why is this? Or is there a better way to set the IP and hostname in an image?
Upvotes: 1
Views: 206
Reputation: 71
You can set the IP address and hostname with --ip and --hostname, respectively when you create a new container with docker run.
Upvotes: 1