I do not know how to achieve that. Now all the ports are exposed to the host machine but I just want to expose one container port (80), not the other (8080). Here is the docker-compose file:
---
version: "3.9"
services:
  app:
    image: sandbox/app
    container_name: app
    volumes:
      - ./src/app:/app/
    expose:
      - "8080"
    restart: unless-stopped
    networks:
      custom-net:
        ipv4_address: 10.0.0.7
  web_server:
    image: nginx:latest
    container_name: proxy
    ports:
      - "80:80"
    networks:
      custom-net:
        ipv4_address: 10.0.0.6
networks:
  custom-net:
    name: custom-net
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 10.0.0.0/8
If I run from the local machine nmap 10.0.0.6, it shows port as open in port 80. This container exposure is the desired one. But when I run nmap 10.0.0.7, it also shows as open 8080 port, how it could be that one? Checking some stackoverflow thread, ports is defined like that:
Expose ports. Either specify both ports (HOST:CONTAINER), or just the container port (a random host port will be chosen).
and expose:
Expose ports without publishing them to the host machine - they’ll only be accessible to linked services. Only the internal port can be specified.
Do I miss some network concepts or do I have wrong docker-compose file?