背景
编写的docker-compose文件内容如下:
version: '2'
services:
MSPW08:
container_name: mspw08
image: web:1.0.0
working_dir: /home/ewang
hostname: mspw08
ports:
- 8089:8080
networks:
outside:
ipv4_address: 192.23.6.19
privileged: true
command:
- /usr/sbin/init
- -c
- |
echo '10.10.110.30 jszx-tdh07'>>/etc/hosts
echo '10.10.110.31 jszx-tdh08'>>/etc/hosts
echo '10.10.110.32 jszx-tdh09'>>/etc/hosts
echo '10.10.110.33 jszx-tdh10'>>/etc/hosts
/usr/sbin/init
stdin_open: true
networks:
outside:
external:
name: wel
该文档实现两个功能:
- 在/etc/hosts追加内容
10.10.110.30 jszx-tdh07
10.10.110.31 jszx-tdh08
10.10.110.32 jszx-tdh09
10.10.110.33 jszx-tdh10
- 容器内部支持命令:systemctl命令
问题
执行上述命令,启动容器后,出现etc/hosts信息没更新,但systemctl命令可以执行:
不满足需求
解决方法
尝试 一
把command模块调整为如下内容:
结果为:hosts内容更新,但systemctl命令不支持,不服务要求,尝试失败
尝试 二
调整command命令如下:
结果为:/etc/hosts内容更新、systemctl命令支持,满足要求
关于方案二,为啥会成功,我目前还没搞明白,搞明白的小伙伴,可以私信我下,谢谢了。