Why do I always fail to run this container and what is the solution to run it?

Notice from the output of docker ps that the postgres container has exited, i.e. it is not running. This is why you cannot exec into it.

When you first ran it, it should have told you

Error: Database is uninitialized and superuser password is not specified.
       You must specify POSTGRES_PASSWORD to a non-empty value for the
       superuser. For example, "-e POSTGRES_PASSWORD=password" on "docker run".

       You may also use "POSTGRES_HOST_AUTH_METHOD=trust" to allow all
       connections without a password. This is *not* recommended.

       See PostgreSQL documentation about "trust":
       https://www.postgresql.org/docs/current/auth-trust.html

which tells you how to run it properly.

For example

docker run -e POSTGRES_PASSWORD=MyReallySecurePassword postgres

lots of output followed by…

2023-10-29 13:20:47.061 UTC [1] LOG:  database system is ready to accept connections
$ docker ps
CONTAINER ID   IMAGE      COMMAND                  CREATED         STATUS              PORTS      NAMES
fbc49cf88ec3   postgres   "docker-entrypoint.s…"   2 minutes ago   Up About a minute   5432/tcp   nostalgic_sutherland
$