在k8s的一个吊舱内,我有2个容器。
容器1:已配置sqlplus客户端以连接到数据库(使用DockerAndSqlClientImage)
容器2:正在运行的数据库(OracleDB映像)
在容器1中,如果我尝试连接到DB,则它将连接到容器2。
container('withDockerAndSqlClient') { //part of jenkinsfile
sh "echo checking db connectivity from container"
sh """
chmod 775 ./checkDBConnection.sh
./checkDBConnection.sh //THIS WORKS
"""
sh label: "docker build", script: "docker build Dockerfile" //THIS FAILS, WHEN TRY TO CONNECT TO DB FROM DOCKER FILE }
从容器1运行DB连接脚本时,它可以工作。但是在从容器1进行docker构建期间运行相同的脚本时,它失败了。
DockerFile
FROM withDockerAndSqlClientImage: latest
USER root
RUN sqlplus -v
RUN chmod 744 /usr/src/package/checkDBConnection.sh
RUN /usr/src/package/checkDBConnection.sh //THIS FAILS, WHEN TRY TO CONNECT TO DB FROM DOCKER FILE
checkDBConnection.sh
echo "Trying to Connect to DB"
c=1
echo "exit" | sqlplus -L username/pwd@sname | grep Connected > /dev/null
while [[ ("$?" -ne "0") && ("$c" -le "10") ]]
do
let c=c+1
echo "Retrying to connect to DB...$c"
sleep 10
echo "exit" | sqlplus -L username/pwd@sname | grep Connected > /dev/null
done
有人可以帮我吗?我试图在容器1中使用docker build --network = host ..它不起作用。