检测到任务失败:docker service create --name db --network backend --mount type=volume,source=db-data,target=/var/lib/postgresql/data postgres

Detected task failure: docker service create --name db --network backend --mount type=volume,source=db-data,target=/var/lib/postgresql/data postgres

我 运行宁 Docker 与 Bash 在 windows 10.

在我的 VM 节点 1 中,当我 运行 这个命令时

docker service create --name db --network backend --mount type=volume,source=db-data,target=/var/lib/postgresql/data postgres:9.4

我得到:

overall progress: 0 out of 1 tasks
1/1: ready
verify: Detected task failure
♥Operation continuing in background.
Use `docker service ps tm3hgzidbr2smnpc7f2tz1w67` to check progress.

为什么任务失败了?

已解决

我遗漏了 postgres 身份验证所必需的参数:-e POSTGRES_HOST_AUTH_METHOD=trust

来自Docker HUB documentation on Postgres

-e POSTGRES_HOST_AUTH_METHOD=trust

Set the auth-method for host connections for all databases, all users, and all addresses. The following will be added to the pg_hba.conf if this option is passed: host all all all $POSTGRES_HOST_AUTH_METHOD.

所以我删除了我的 db 服务

docker service rm db

并将其替换为

docker service create --network backend --mount type=volume,source=db-data,target=/var/lib/postgresql/data --name db -e POSTGRES_HOST_AUTH_METHOD=trust postgres:9.4