Search code examples
dockerdocker-composeyaml

Docker ports mapping in the .yml file has not changed the container port


consider a docker .yml file like this:

version: '3.8'
services:
  postgres:
    image: postgres:13
    restart: always
    environment:
      - POSTGRES_USER=prisma_pg
      - POSTGRES_PASSWORD=benchmark
    volumes:
      - postgres:/var/lib/postgresql/data
    ports:
      - '5454:5432'
volumes:
  postgres:

after I ran these commands:
docker-compose -f ./docker-compose.yml up -d
docker-compose ps
its State is UP and the ports column showing 0.0.0.0:5432->5432/tcp illustrates that the running port is not set to 5454->5432 as we described in the yaml file,

How can we fix it to map the port correctly?

Edit: the file is saved in the same directory and there is no other container running before or after this one:

here is the screenshot, which probably helps: enter image description here


Solution

  • I copied the docker file out of project space and it WORKED!

    the problem was aroused from a merge that had made a similarly named directory in the project. so the port changes had been applied to the other one. So the container and docker are OK( I appreciated all the people's efforts, especially @msrumon who helped me in this important part to forget about the config and seek another reason)