Changing a postgres containers server port in Docker Compose

后端 未结 2 655
闹比i
闹比i 2021-02-02 07:22

I am trying to deploy a second database container on a remote server using Docker compose. This postgresql server runs on port 5433 as opposed to 5432 as used by the first postg

2条回答
  •  遥遥无期
    2021-02-02 07:50

    Some people may wish to actually change the port Postgres is running on, rather than remapping the exposed port to the host using the port directive. To do so, use command: -p 5433

    In the example used for the question:

    db:
      image: postgres:latest
      environment:
        POSTGRES_PASSWORD: route_admin
        POSTGRES_USER: route_admin
      expose:
        - "5433" # Publishes 5433 to other containers but NOT to host machine
      ports:
        - "5433:5433"
      volumes:
        - ./backups:/home/backups
      command: -p 5433
    

    Note that only the host will respect the port directive. Other containers will not.

提交回复
热议问题