docker 启动成功但无法访问,docker正在运行,但无法在服务器上访问

I have stages for Jenkins jobs to test and deploy my nodejs with docker, I run docker on port 3000 but when I tried to browser my ip-server:3000, it doesn't work and nothing

my dockers are running

here is my Jenkinsfile

node {

try {

stage('Checkout') {

checkout scm

}

stage('Environment') {

sh 'git --version'

echo "Branch: ${env.BRANCH_NAME}"

sh 'docker -v'

sh 'printenv'

}

stage('Build Docker test'){

sh 'docker build -t crud-test -f Dockerfile.test --no-cache .'

}

stage('Docker test'){

sh 'docker run --rm crud-test'

}

stage('Clean Docker test'){

sh 'docker rmi crud-test'

}

stage('Deploy'){

if(env.BRANCH_NAME == 'master'){

sh 'docker build -t crud --no-cache .'

sh 'docker run -d -p 3000:3000 -e DB_USERNAME=myusername -e DB_PASSWORD=12345678 -e DB_NAME=employee crud'

}

}

}

catch (err) {

throw err

}

}

Dockerfile:

# Extending image

FROM node:carbon

RUN apt-get update

RUN apt-get upgrade -y

RUN apt-get -y install autoconf automake libtool nasm make pkg-config git apt-utils

# Create app directory

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

# Versions

RUN npm -v

RUN node -v

COPY ./server/ /usr/src/app

RUN npm install

# Port to listener

EXPOSE 3000

# Environment variables

ENV PORT 4000

ENV DB_USERNAME myusername

ENV DB_PASSWORD 12345678

ENV DB_NAME employee

# Main command

CMD [ "npm", "run", "dev" ]

I run Jenkins via docker-compose on my ubuntu server,

is that something I missing or wrong ??

because my goal here using Jenkins to test my server and after the test successfully it gonna deploy my Nodejs on my ubuntu server

so after building finish on Jenkins, I could browser my server API on the browser to make sure it works on ip-sever:3000

but on the above pipeline, is that correct that job do every time I push to master, my server API will be updated without click build now on Jenkins? if not, how to configure it?

I am also don't know how to hide my ENV, so I show up on my stage Jenkinsfile because on multibranches pipeline does not have any option for env parameters

解决方案

I can see your env variable port 4000 is that your server port ? If it's so you have to change docker run command to map port 4000 to work on port 3000 in your host, or you can change your env variable Port to be 3000

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值