Changing a postgres containers server port in Docker Compose

后端 未结 2 658
闹比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:51

    I'm assuming postgres is running on port 5432 in the container and you want to expose it on the host on 5433.

    This ports strophe:

    ports:
        - "5433:5432"
    

    will expose the server on port 5433 on the host. You can get rid of your existing expose strophe in this scenario.

    If you only want to expose the service to other services declared in the compose file (and NOT localhost), just use the expose strophe and point it to the already internally exposed port 5432.

    Bear in mind, the EXPOSE directive doesn't actually do anything (it's more of a hint for you). Port 5432 will be exposed to the other services declared in the compose file with or without the directive.

提交回复
热议问题