Home > front end >  Docker container accessible to localhost when container is runned manually but not when runned by a
Docker container accessible to localhost when container is runned manually but not when runned by a

Time:10-24

im running a spring boot app on a container exposed on PORT:8084 . the image is pushed to docker hub then i have this script on Jenkinsfile that runs the image on a container :

stage('Deploying the image into a container'){
        steps {
            echo "Installing the app "
            sh 'docker run $imagename:$BUILD_NUMBER -p 8084:8084 -d --name $dockerImage  '
        }
    }

the app is not accessible on 'localhost:8084' the container is up and when running docker-ps :

33f8cb4d98e6   28609002/time_sheet_dev_ops:38   "java -jar time_shee…"   29 minutes ago   Up 3 seconds   8084/tcp   focused_merkle

but when i run the image manually in my terminal , the app is accessible :

docker run -d -p 8084:8084 imagename

when running docker ps :

50715adaa50c   28609002/time_sheet_dev_ops:latest   "java -jar time_shee…"   8 seconds ago   Up 7 seconds   0.0.0.0:8084->8084/tcp, :::8084->8084/tcp   distracted_shamir

the only difference is in port output, i tried adding -b 0.0.0.0 to the run command , also tried accessing the app via '127.0.0.1:8084' and many other solutions yet nothing seems to make it work whithin the CI/CD pipeline

CodePudding user response:

Try options after run and before image.

Here is docker run --help output:

 docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

So, proper command:

sh 'docker run -p 8084:8084 -d --name $dockerImage $imagename:$BUILD_NUMBER'
  • Related