简体   繁体   中英

How to expose port to external host in docker?

I am trying to expose a port in docker container, and try to connect application from external host but i am unable to connect.

curl request:

curl http://localhost:4400
curl: (56) Recv failure: Connection reset by peer

run command:

docker run -p 4400:3002  dev/my-node-app

Dockerfile:

FROM ubuntu:20.04

RUN apt-get update; \
    apt-get install -y curl gnupg; \
    curl -sL https://deb.nodesource.com/setup_10.x | bash -; \
    apt-get install -y nodejs; \
    rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

COPY . .

EXPOSE 3002

ENTRYPOINT ["npm", "run", "server:dev"]

Also tried below Dockerfile

FROM node:12.19.0

# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# Bundle app source
COPY . .

EXPOSE 3002
CMD ["npm", "run", "server:dev"]

But now getting error:

Module build failed: Error: /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/src/app/node_modules/node-sass/vendor/linux-x64-64/binding.node)

I think i am running it correctly but somehow there is an error in my Dockerfile, if anyone help me I'd really be grateful.

Thanks

curl http://localhost:4400
curl: (56) Recv failure: Connection reset by peer

It indicates that port does not point to an application.

The application is pointing to 127.0.0.1, which should be pointing to 0.0.0.0 inside Docker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM