Docker is listening to port specified in run command

208 views Asked by At

I created a pipeline in Jenkins which takes an app from Github, builds the app, and then builds an image and then finally runs that image with the app.

the Dockerfile is:

FROM javastreets/mule:latest

COPY ./target/jenkins-demo-api-1.0.0-1.0.0-SNAPSHOT-mule-application.jar /opt/mule/apps/ 

CMD [ "/opt/mule/bin/mule"]

here jenkins-demo-api-1.0.0-1.0.0-SNAPSHOT-mule-application.jar is the app that is built in Jenkins from Github.

the pipeline script is as:

pipeline {
    agent any
    
    tools{
        maven 'M3'
    }
    stages {
        stage('git pull'){
            steps{
                git branch: 'master', credentialsId: '025fbee3-18cc-4298-ac9b-adac*****', url: 'https://github.com/treadston-e/mule-jenkins.git'
            }
        }
        stage('Build') {
            steps {
                bat "mvn clean package"
            }
        }
        stage('build image'){
            steps{
                bat 'docker build -t docker-demo .'
            }
        }
        stage('run image'){
            steps{
                bat 'docker run -d -p 127.0.0.1:8081:8081 docker-demo'
            }
        }
       
    }
}

the pipeline executes successfully but when I try to hit, http:localhost:8081 response I receive is This page isn’t working

what should I do?

1

There are 1 answers

0
Ihor Shylo On

The localhost you are referring to is a localhost of the docker container which is not the same as of your client. Try to specify network in your docker run command.

docker run -d --network host -p 8081:8081 docker-demo

if you would like to check on which IP address the bridge is running, you can check it as follows:

docker network inspect bridge