Jenkinsfile pipeline: access one docker container from another

Viewed 1304

I have a Jenkinsfile, where I declared 2 stages:
Stage 1 - where I serve web-server which is create from nginx docker image
Stage 2 - Running another docker container which is create out of node image and try to connect to container#1
When I run this pipeline I keep getting this error (7) Failed to connect to 127.0.0.1 port 80: Connection refused I'm new to jenkins-pipeline, docker and devOps in overall, but it kinda looks like that containers are running in different networks or environments or something.

My Jenkinsfile:

pipeline {
    agent any
    stages {
        stage('Serve') {
            agent {
                docker { 
                    image "nginx" 
                    args "--name nginx-server -v ${WORKSPACE}/src:/usr/share/nginx/html:ro -d -p 8080:80"
                    reuseNode true
                } 
            }
            steps {
                sh 'apt-get update' 
                sh 'apt-get install -y --no-install-recommends curl'
                sh 'rm -rf /var/lib/apt/lists/*'
            }
        }
        stage('Connect to server') {
            agent { docker { image 'node' } }
            steps {
                sh 'curl http://localhost:8080'
            }
        }
    }
}
1 Answers

Please specify operating system type

attached full log

If you OS is windows 10 then you need to update docker setting also.
step 1 : goto docker setting
step : 2 select General -- > Checked Expose daemon on tcp://localhost:2375 without TLS
Related