Home > Net >  Docker runs only on Port 80
Docker runs only on Port 80

Time:10-16

I am unable to run my docker image on Port 4000, even though I can run it on Port 80. What am I doing wrong here?

FROM node:latest as build
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:latest
COPY --from=build /usr/src/app/dist/admin /usr/share/nginx/html
EXPOSE 4200

I'm creating the image using the following command:

docker build --pull --rm -f "DockerFile" -t admin1:v1 "."

When I run it on port 80, I'm able to use it:

docker run --rm -d -p 4200:4200/tcp -p 80:80/tcp admin1:v1

However, when I run the following command, I'm unable to use it:

docker run --rm -d -p 4200:4200/tcp -p 4000:4000/tcp admin1:v1

I have researched similar questions online, but I haven't been able to fix the problem. Any suggestion will be greatly appreciated!

CodePudding user response:

You need to map the docker container port to the docker host port.

Try the following Command

docker run --rm -d -p 4200:4200/tcp -p 4000:80/tcp admin1:v1

The following is the extract from the Docker Documentation

-p 8080:80  Map TCP port 80 in the container to port 8080 on the Docker host.

You can refer the link for further information. Docker Documentation

  • Related