Docker:无法为正在运行的容器指定端口 [英] Docker: Unable to specify port for a running container

查看:1151
本文介绍了Docker:无法为正在运行的容器指定端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Docker的新手。我正在使用Mac,因此在HortonWorks Sandbox Virtual Box中安装了Docker。



我正在尝试从Ubuntu基本映像创建2个容器。一个容器在其上运行nodej,其他的使用mysql。



我可以创建一个容器,并在Docker ps下列出,但是当我尝试为该容器指定端口,它不会显示任何错误,但端口没有设置。



用于向正在运行的容器添加端口的命令:

  docker run -p 8080:8080 nodejsapp 

其中节点jsapp是我的图像名称1容器。



任何帮助将非常感激。谢谢。

解决方案

很难说没有看到你的Dockerfile,而且不知道你看到什么错误信息,但我的猜测是你没有告诉NodeJS要运行哪个端口。 NodeJS中的约定是使用 NODE_PORT 环境变量来执行此操作:

 码头运行-e NODE_PORT = 8080 


I am a newbiew to Docker. I am using Mac hence have installed Docker in HortonWorks Sandbox Virtual Box.

I am trying to create 2 containers out of a Ubuntu base image. One container runs nodejs on it and other with mysql.

I am able to create a container and it lists under Docker ps, but when I try to specify port for that container, it doesn't show me any error, but the port is not getting set.

Command used to add port to a running container:

docker run -p 8080:8080 nodejsapp

where node jsapp is my Image name of 1 container.

Any help would be really appreciated. Thanks.

解决方案

It's hard to say without seeing your Dockerfile and without knowing what error messages you're seeing, but my guess is that you're not telling NodeJS what port to run on. The convention in NodeJS is to do this with the NODE_PORT environment variable:

docker run -e NODE_PORT=8080

这篇关于Docker:无法为正在运行的容器指定端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆