This took me a while to figure out from scratch. The most important thing is to know that docker pull postgres retrieves an image from the main Docker registry.

After you retrieve the image, you run a container with parameters, which are used in its entrypoint file, to set up a database. But you still have to know to mount a volume from the “host” (the physical machine) and to expose ports.

docker run -p 5432:5432 --rm --name postgres_container -d -v /var/www/postgres_data:/var/lib/postgresql/data -e POSTGRES_DB=yourdb -e POSTGRES_USER=youruser -e POSTGRES_PASSWORD=yourpassword postgres

Note here that postgres (the last argument to run) is the name of the image which is what you get when you run the pull from Docker.