Recommand · May 14, 2022 0


Docker Compose ports are being ignored on up

This is my Docker Compose file containing 4 api containers:

version: '3.4'

services:
  api1.api:
    image: ${DOCKER_REGISTRY-}api1
    build:
      context: .
      dockerfile: Api1.Api/Dockerfile
    networks: 
    - dev-network
    ports:
    - "62000:443"
    - "62001:80"

  api2.api:
    image: ${DOCKER_REGISTRY-}api2
    build:
      context: .
      dockerfile: Api2.Api/Dockerfile
    networks: 
    - dev-network
    ports:
    - "62002:443"
    - "62003:80"


  api3.api:
    image: ${DOCKER_REGISTRY-}api3
    build:
      context: .
      dockerfile: Api3.Api/Dockerfile
    networks: 
    - dev-network
    ports:
    - "62004:443"
    - "62005:80"


  api4.api:
    image: ${DOCKER_REGISTRY-}api4
    build:
      context: .
      dockerfile: Api4.Api/Dockerfile
    networks: 
    - dev-network
    ports:
    - "62006:443"
    - "62007:80"
networks:
  dev-network:
      name: dev-network

I have set the ports but when I run docker-compose up -d, the results are that either 1 or 2 of the apis will have the specified ports only. The rest will be randomly generated or even blank?

I have to manually restart that container before it generates a random port.

Am I missing a command or step? How can I get my docker-compose to follow the ports that have been set?




You may also like…




amazon-web-services android angular api arrays c# css dart dataframe django docker excel express firebase flutter html ios java javascript jquery json kotlin laravel linux list mongodb mysql node.js pandas php postgresql python python-3.x r react-native reactjs regex spring spring-boot sql sql-server string swift typescript vue.js