[英]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.