Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
298 views
in Technique[技术] by (71.8m points)

node.js - Dockerfile: how to forward ports?

I have a nodejs application. It runs in a container. I need to forward ports to the host machine. I ask for your help.

Dockerfile:

FROM node:14
WORKDIR /usr/src/app
COPY . .
RUN yarn
EXPOSE 4200

try:

docker run -p 127.0.0.1:4200:4200  -t -d --name vub vub
# or
docker run -p 4200:4200  -t -d --name vub vub

My application is running on port 4200. The operation of the application can be checked through

curl http://localhost:4200/

In the container, the application works correctly.

Why can't I see the application on the host machine(http://localhost:4200/)? How to fix it?

question from:https://stackoverflow.com/questions/65846526/dockerfile-how-to-forward-ports

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You should make sure that there's a server running, with express or something responsible for the same functionalities. If all you're doing is printing a "hello world" on the terminal the container will exit.

Your question could be improved with the full source code.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...