Current Setup requires Docker Components (Dockerfile, requirements.txt, Jenkinsfile) to be separate from Source Code. Docker Components resides in a directory whereas the Source Code resides in another directory. Design so far is to build the Docker Image with the Docker Components and run the Docker Image, and the Source Code is inserted into the root directory of the container. Model so far works on the CMD terminal however when translating over to the Jenkins Pipeline, the docker exec command is not recognised on the Jenkins Pipeline
Stages run well on the Jenkins Pipeline until the stage to insert Source Code as a volume. When running $ docker exec -it source-container bash, below is the error log:
C:WINDOWSsystem32configsystemprofileAppDataLocalJenkins.jenkinsworkspaceSource-Code-Pipeline>docker exec -ti source-container bash
the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty'
When prefixing with 'winpty', pipeline does not execute well too. How can I go about in resolving this issue?
Below is the Jenkinsfile to depict the Pipeline flow:
node {
checkout scm
stage ('Create Docker Registry') {
bat 'docker run -d -p 5000:5000 --restart=always --name registry registry:2'
}
stage ('Build Docker Image') {
def image = docker.build("docker-csv", '.')
}
stage ('Tag and Push Docker Image') {
bat 'docker tag docker-csv localhost:5000/docker-csv'
bat 'docker push localhost:5000/docker-csv'
}
stage ('Pull Docker Image from Local Registry') {
bat 'docker pull localhost:5000/docker-csv'
}
stage ('Insert Source Code as Volume into Container') {
bat 'docker run --name source-container -d -v /c/Users/z0048yrk/Desktop/Source-Code:/root localhost:5000/docker-csv tail -f /dev/null'
bat 'docker exec -it source-container bash'
bat 'cd root'
bat 'python test.py > output.csv'
}
stage ('Copy output.csv into desired directory') {
dir("C:\Users\z0048yrk\Desktop\LTA\new-demo") {
bat 'docker cp source-container:/root/output.csv'
}
}
}
question from:
https://stackoverflow.com/questions/65896729/how-to-access-within-docker-container-in-jenkins-pipeline 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…