Docker: Unable to specify port for a running container

情到浓时终转凉″ 提交于 2019-12-12 04:54:42

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/28510562/docker-unable-to-specify-port-for-a-running-container

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!