首页 \ 问答 \ nodejs app的Docker端口转发(Docker port forwarding for nodejs app)

nodejs app的Docker端口转发(Docker port forwarding for nodejs app)

我在为nodejs app配置docker时遇到问题。

我之前已经为php和rails设置了容器,端口转发工作完美无缺,但是对于这个实例我似乎无法让它工作。

运行: docker ps ,我得到以下内容:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a60f9c82d600        29c7d94a8c58        "/bin/sh -c 'npm s..."   5 seconds ago       Up 3 seconds        3000/tcp            romantic_albattani

你可以看到我没有得到通常的: 0.0.0.0:3000->3000/tcp0.0.0.0:3000->3000/tcp ,我期待。

docker-compose ps给出:

Name   Command   State   Ports
------------------------------

我的docker-compose.yml:

web:
  build: .
  volumes:
    - .:/app
  volumes_from:
    - box
  ports:
    - "3000:3000"

box:
  image: busybox
  volumes:
    - /node_modules

我的Docker文件:

FROM node:8.7.0

# The base node image sets a very verbose log level.
ENV NPM_CONFIG_LOGLEVEL warn

WORKDIR /tmp
COPY package.json /tmp/
RUN npm install

WORKDIR /app
ADD . /app
RUN cp -a /tmp/node_modules /app/

#ENV PORT=3000
EXPOSE 3000
CMD npm start

我正在运行命令: docker-compose up --build

在这一点上的任何帮助表示赞赏。

我不知道码头检查是否有用,但如果有,请告诉我,我也会发布。

编辑:更改了我的Dockerfile以遵循答案。


I'm having problems configuring docker for my nodejs app.

I have previously set up containers for both php and rails with port forwarding working flawlessly, but for this instance i can't seem to get it to work.

Running: docker ps, i get the following:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
a60f9c82d600        29c7d94a8c58        "/bin/sh -c 'npm s..."   5 seconds ago       Up 3 seconds        3000/tcp            romantic_albattani

As you can see I'm not getting the usual: 0.0.0.0:3000->3000/tcp that I am expecting.

docker-compose ps gives:

Name   Command   State   Ports
------------------------------

My docker-compose.yml:

web:
  build: .
  volumes:
    - .:/app
  volumes_from:
    - box
  ports:
    - "3000:3000"

box:
  image: busybox
  volumes:
    - /node_modules

My Docker file:

FROM node:8.7.0

# The base node image sets a very verbose log level.
ENV NPM_CONFIG_LOGLEVEL warn

WORKDIR /tmp
COPY package.json /tmp/
RUN npm install

WORKDIR /app
ADD . /app
RUN cp -a /tmp/node_modules /app/

#ENV PORT=3000
EXPOSE 3000
CMD npm start

I'm running the command: docker-compose up --build

Any help at this point is appreciated.

I don't know if a docker inspect would be useful, but if so, tell me and i will also post it.

Edit: Changed my Dockerfile to follow the answer.


原文:https://stackoverflow.com/questions/46973944
更新时间:2022-03-26 12:03

最满意答案

简短的回答:它可以是,有一些警告。 没有明确的答案,这就是为什么浏览器嗅探广泛不受欢迎的原因之一。

较长的回答: IE用户代理字符串在不同条件下会有所不同。 例如,IE11的企业模式会报告一个IE8用户代理字符串。 (链接的文章提供了一个相对详尽的变体列表。)

一般建议是使用功能检测,逐步增强和优雅回退为不支持某些功能的浏览器提供内容体验。 或者,可能会有一个polyfill或替代方法帮助。 CanIUse是找出替代品的好资源。


Short answer: It can be, with certain caveats. There's no definitive answer and this is one reason why browser sniffing is widely discouraged.

Longer answer: The IE user agent string varies under different conditions. IE11's Enterprise Mode, for example, reports an IE8 user agent string. (The linked article provides a relatively exhaustive list of variations.)

The general recommendation is to use feature detection, progressive enhancement, and graceful fallback to delivery a content experience for browsers that don't support certain features. Alternatively, there may be a polyfill or alternate approach that helps. CanIUse is a good resource for figuring out alternatives.

相关问答

更多
  • 如果命令成功,则execCommand()返回true ,否则返回false 。 因此你可以这样做: if (!document.execCommand('FormatBlock', null, 'H1')) { document.execCommand('FormatBlock', null, '

    '); } 虽然其他浏览器似乎也适用于

    ... execCommand() returns true if the command is successful, or false oth ...

  • 你必须修改你的CSS来对齐所有浏览器中的下拉箭头,包括IE11。 请使用这个CSS。 #nav li{ display: inline-block; position: relative; /*Added Line*/ } #nav ul li.active:after { border-left: 20px solid transparent; border-right: 20px solid transparent; content: ""; border-top: 13px solid rg ...
  • 编辑2016年11月18日 此代码也可以工作( 对于那些喜欢其他解决方案,不使用ActiveX的用户 ) var isIE11 = !!window.MSInputMethodContext && !!document.documentMode; // true on IE11 // false on Edge and other IEs/browsers. 原始答案 为了检查Ie11,可以使用:(测试) (或运行这个 ) !(window.ActiveXObject) && "ActiveXOb ...
  • 你指定一个有效的doctype吗? 通过将Internet切换到标准模式,您可以使Internet Explorer更具兼容性。 http://msdn.microsoft.com/en-us/library/bb250395.aspx#cssenhancements_topic2 您是否使用浏览器重置CSS文件? 这可以帮助将版本合在一起。 http://meyerweb.com/eric/tools/css/reset/ 请注意IE的CSS错误: http : //www.positionisevery ...
  • 在MDN上有一个用于CustomEvent构造函数的IE polyfill 。 将自定义事件添加到IE,然后使用该工具。 (function () { if ( typeof window.CustomEvent === "function" ) return false; //If not IE function CustomEvent ( event, params ) { params = params || { bubbles: false, cancelable: false, ...
  • 转到控制面板 - > 程序 - > 程序和功能 转到Windows功能并禁用Internet Explorer 11 然后点击显示已安装的更新 搜索Internet Explorer 右键单击Internet Explorer 11 - > 卸载 使用Internet Explorer 10执行相同操作 重启你的电脑 在这里安装Internet Explorer 10 (旧破碎的链接 ) 我觉得没关系 Go to Control Panel -> Programs -> Programs and featu ...
  • 简短的回答:它可以是,有一些警告。 没有明确的答案,这就是为什么浏览器嗅探广泛不受欢迎的原因之一。 较长的回答: IE用户代理字符串在不同条件下会有所不同。 例如,IE11的企业模式会报告一个IE8用户代理字符串。 (链接的文章提供了一个相对详尽的变体列表。) 一般建议是使用功能检测,逐步增强和优雅回退为不支持某些功能的浏览器提供内容体验。 或者,可能会有一个polyfill或替代方法帮助。 CanIUse是找出替代品的好资源。 Short answer: It can be, with certain c ...
  • 你只需要flex:1; 它将解决IE11的问题 #wrapper { display: -webkit-flex; display: -moz-flex; display: -ms-flexbox; display: -o-flex; display: flex; -webkit-flex-direction: row; -moz-flex-direction: row; -ms-flex-direction: row; -o-flex-direction: row; flex-direction: row ...
  • 简而言之:不要在IE中使用像document.createElement(“div”)这样的DOM方法来创建标记。 改为使用字符串构建您的HTML。 如果您必须使用DOM方法,请确保不要多次向页面添加元素。 也就是说,创建一个主容器,添加所有内容,然后作为最后一步调用document.body.appendChild(“div”)(其中“div”是您的主容器)。 这将最大限度地减少将继续的重新渲染量。 Short answer: don't use DOM methods like document.cre ...
  • EMSL可以双向工作,您可以将首选浏览器标记为边缘,并且它会启动边缘。 如果您有能力将策略推送到用户的计算机上,这只会起作用。 否则无法自动打开任何浏览器。 The EMSL works both ways, you can mark the preferred browser as edge and it will launch edge. This will only work if you have the ability to push a policy to your user's machine ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)