Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
431 views
in Technique[技术] by (71.8m points)

How to access within Docker Container in Jenkins Pipeline

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...