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/tcp
:0.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
最满意答案
简短的回答:它可以是,有一些警告。 没有明确的答案,这就是为什么浏览器嗅探广泛不受欢迎的原因之一。
较长的回答: 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 ...
-
Internet Explorer 9,10和11事件构造函数不起作用(Internet Explorer 9, 10 & 11 Event constructor doesn't work)[2022-03-08]
在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 ...