Docker正在监听运行命令中指定的端口 [英] Docker is listening to port specified in run command

查看:211
本文介绍了Docker正在监听运行命令中指定的端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jenkins中创建了一个管道,该管道从Github中获取一个应用程序,构建该应用程序,然后构建一个映像,然后最终使用该应用程序运行该映像。

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.

Dockerfile是:

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"]

此处 jenkins-demo-api-1.0.0-1.0.0-SNAPSHOT-mule-application.jar 是内置的应用

管道脚本如下:

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'
            }
        }
       
    }
}

管道成功执行,但是当我尝试点击 http:localhost:8081 我收到的回复是此页面无法正常工作

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

我该怎么办?

推荐答案

您所指的localhost是docker容器的localhost,与Docker容器的localhost不同您的客户。尝试在docker run命令中指定网络。

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

如果您要检查网桥正在运行的IP地址,可以按以下方式进行检查:

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

docker network inspect bridge

这篇关于Docker正在监听运行命令中指定的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆