简体   繁体   English

无法在Centos7容器中公开Node Express应用程序的端口

[英]Can`t expose port for node express app in Centos7 container

I am creating an image node HTTP server app. 我正在创建图像节点HTTP服务器应用程序。 App run on 3000 port. 应用程序在3000端口上运行。 But I can`t reach it from localhost. 但是我无法从本地主机访问它。

Dockerfile: Dockerfile:

FROM centos:7

RUN curl --silent --location https://rpm.nodesource.com/setup_8.x | bash -
RUN yum install -y nodejs
RUN node -v
#yarn
RUN curl --silent --location https://dl.yarnpkg.com/rpm/yarn.repo | tee /etc/yum.repos.d/yarn.repo
RUN rpm --import https://dl.yarnpkg.com/rpm/pubkey.gpg
RUN yum install -y yarn
# Set up mongodb yum repo entry
RUN echo -e "\
[mongodb-org-4.0]\n\
name=MongoDB Repository\n\
baseurl=https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/\n\
gpgcheck=1\n\
enabled=1\n\
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc\n" >> /etc/yum.repos.d/mongodb.repo

# Install mongodb
RUN yum update -y && yum install -y mongodb-org

COPY server.js /home/server.js
COPY start.sh  /home/start.sh
COPY package.json  /home/package.json

# Install js dependencies
RUN cd /home
RUN yarn

EXPOSE 3000

ENTRYPOINT ["sh", "/home/start.sh"]

start.sh: start.sh:

echo "HELLO FROM SH FILE!"
yarn

node ./server.js

server.js: server.js:

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

For build container I use: 对于构建容器,我使用:

docker build -t "gepick:dev1" .

For start container I use: 对于启动容器,我使用:

docker run -i -t 2f0fd105f299 -p 3000:3000 /bin/bash

I sure that app is up and running because console output is: 我确定该应用程序已启动并正在运行,因为控制台输出为:

Example app listening on port 3000!

But when I try to run app throw browser on localhost:3000 I get: 但是当我尝试在localhost:3000上运行应用抛出浏览器时,我得到了:

This site can't be reached

What is it docker run -i -t 2f0fd105f299 -p 3000:3000 /bin/bash ??? docker run -i -t 2f0fd105f299 -p 3000:3000 /bin/bash

Your launch command should be 您的启动命令应为

docker run -i -t -p 3000:3000 2f0fd105f299

Puting exposal arguments after image ID just passes them to your start.sh script. 将曝光参数放在图像ID后面只是将它们传递给您的start.sh脚本。 Docker only reads arguments before image name/ID. Docker仅在映像名称/ ID之前读取参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法在 centos 服务器上运行 node express - Can't run node express on centos server 无法在Windows的节点容器中运行示例Express应用 - Can't run sample express app in node container on Windows 无法访问该站点centos7 - nodejs This site can’t be reached centos7 如何在CentOS7上使用软件集合(scl)自动启动节点/快速应用程序(使用pm2)并安装了节点 - How do I automatically start a node/express app (with pm2), having node installed using software collections (scl), on CentOS7 centos7,为什么我不能在我的服务器上安装Express? - centos7 , Why i can not install express into my server? 无法访问在 Node.js 中创建的 localhost:PORT 和 express - Can't reach localhost:PORT created in Node.js and express 在Centos7 Apache服务器上运行Node.js应用 - Running nodejs app on Centos7 apache server 为什么我在CentOS中使用node.js无法连接8080端口? - Why I can't connect port 8080 using node.js in CentOS? 将带有Express App的节点部署到DigitalOcean:App无法在端口3000上运行 - Deploying Node w/ Express App to DigitalOcean: App Won't Run On Port 3000 运行 React 应用程序的 docker 容器在哪个端口? Reacts 的默认端口或来自 Dockerfile 的 EXPOSE? - On what PORT is my docker container with a React app running? Reacts' default PORT or EXPOSE from Dockerfile?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM