Edit:
I did a test with all your files in the same directory and that works like a charm. The only thing I did change was that my docker-compose.yml looks like this and does not build form the ./post directory.
docker@debian:~/test$ docker-compose up
WARNING: Found orphan containers (test_postgres_1) for this project. If you removed or renamed this service in your compose file, you can run this command with the --remove-orphans flag to clean it up.
Recreating test_php_1 … done
Attaching to test_php_1
test_php_1 exited with code 0
In your first docker-compose, you named the service postgres and started the services. Then you changed the service name to php and tried to do a docker-compose up again. That leaves the service and container state of the previous one in an orphaned state, as it states in the error message.
To fix this, run the command docker-compose down --rmi all --remove-orphans
I have been thought to either do docker-compose build && docker-compose upor docker-compose --build up.
When running in a development environment, I like to use the --force-recreate flag also.