【发布时间】:2020-08-21 04:20:20
【问题描述】:
我的Docker Version - 19.03.8, build afacb8b
我已经从DockerHub 中提取了ubuntu:18.04。然后按照以下步骤将两个新行添加到我的 docker 映像的 /etc/hosts 文件中。
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
在我的容器的/etc/hosts 文件中添加以下两行(56.57.58.59 example1.com 和56.57.58.60 example2.com)后,保存后退出,最后我提交了我的容器。
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
所以在新图像中我看不到我在/etc/hosts 文件中所做的更改。如果上述步骤有问题,请纠正我。
【问题讨论】:
-
你几乎不想使用
docker commit;使用docker build从 Dockerfile 构建映像是更好的做法,并且您将写下当一年内基础映像中存在必须修复的关键安全问题时如何重建映像。同样,设置 DNS 系统(如 BIND、DNSMasq 或像 Consul 这样的服务发现系统)将比尝试在多个位置复制/etc/hosts文件更易于维护。
标签: docker