Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Meaning of PORTS column of Docker container ls

I’m getting this value on the PORTS column of a docker container ls entry (a container for a react app served by Nginx):

PORTS
80/tcp, 0.0.0.0:40000->40000/tcp, :::40000->40000/tcp

I know the second part is IPv4 mapping and the third is IPv6. I don’t understand the meaning of the 80/tcp, but I think it’s what really makes the app accessible from the internet, because if I use mapping "80:80" it works, but now with "40000:40000" it doesn’t.

My project has a structure like this, so it can build multiple projects at once with compose:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

|
|- client (a React app)
|  |- Dockerfile-client
|- .env.prod
|- docker-compose.yml

The docker-compose.yml looks like this:

version: '3.7'
services:
  client:
    build:
      dockerfile: ./client/Dockerfile-client
      context: ./ # so the .env.prod file can be used by React
    container_name: client
    env_file:
      - .env.prod # enabled to apply CLIENT_PORT var to Dockerfile-client
    ports:
      - "${CLIENT_PORT}:${CLIENT_PORT}"
  # others

All the variables are defined in .env.prod (CLIENT_PORT is 40000), and I run compose like `docker compose –env-file .env.prod up", and it doesn’t bring errors.

Here’s the Dockerfile that builds the client container:

# build env
FROM node:13.13-alpine as build
WORKDIR /app
COPY ./client/package*.json ./
RUN npm ci
COPY ./client/ ./
COPY ./.env.prod ./
RUN mv ./.env.prod ./.env
RUN npm run build

# production env
FROM nginx:stable-alpine
COPY --from=build /app/build /usr/share/nginx/html
EXPOSE ${CLIENT_PORT}
CMD ["nginx", "-g", "daemon off;"]

It would all work fine if I mapped "80:80", but my problem is how is that 80/tcp there in the ls output when there’s no "80" to be seen in the files? Might it be because of Nginx?

>Solution :

80/tcp is from nginx which listens by default on this port.

Correct port mapping in this case will be 4000:80

OR

If you want nginx to listen on other port like 4000 update listen parameter in nginx.conf file to that port

http {
    server {
        listen 4000;

        }
}

And then use port mapping as 4000:4000

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading