源由不表,暂且略过。 直接说workaround.
因为openshift的模式,/etc/resolv.conf是在pod生成的时候插入的,写入的是宿主机的ip作为dns的寻址,如果需要修改的化,需要在容器生成以后
脚本启动以前进行修改。
1.打开scc对root权限的控制
$ oc create serviceaccount useroot $ oc adm policy add-scc-to-user anyuid -z useroot $ oc patch dc/mytomcat --patch '{"spec":{"template":{"spec":{"serviceAccountName": "useroot"}}}}'
2.修改应用镜像, 构建一个Dockerfile
[root@master tomcat]# cat Dockerfile FROM docker-registry.default.svc:5000/myproject/tomcat:8-slim COPY startapp.sh /usr/local/tomcat/bin/startapp.sh CMD ["/usr/local/tomcat/bin/startapp.sh"]
其中startapp.sh为
[root@master tomcat]# cat startapp.sh #!/bin/bash echo "startup ...." cp /etc/resolv.conf /etc/resolv.conf1 sed -i "s/:5/:5 single-request/" /etc/resolv.conf1 cp /etc/resolv.conf1 /etc/resolv.conf /usr/local/tomcat/bin/catalina.sh run
3.推送镜像到仓库
docker build -t docker-registry.default.svc:5000/myproject/mytomcat:8-slim . docker push docker-registry.default.svc:5000/myproject/mytomcat:8-slim
查看结果