psql:无法翻译主机名“ somePostgres”,地址:未知的名称或服务 [英] psql: could not translate host name "somePostgres" to address: Name or service not known
问题描述
我正在docker中构建java spring mvc应用程序,而ockefile构建涉及与postgres容器进行交互。每当我运行 docker-compose up
时,dockerfile中与海报交互的步骤有时会因异常而失败
I am building a java spring mvc application in docker and dockefile build involves interacting with postgres container. Whenever i run docker-compose up
the step in dockerfile which interacts with the postrges sometimes fails with an exception
psql:无法将主机名 somePostgres转换为地址:名称或服务未知
失败
psql: could not translate host name "somePostgres" to address: Name or service not known FAILED
失败:生成失败并显示
DockerCompose文件:
DockerCompose file:
abcdweb:
links:
- abcdpostgres
build: .
ports:
- "8080:8080"
volumes:
- .:/abcd-myproj
container_name: someWeb
abcdpostgres:
image: postgres
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
container_name: somePostgres
somePostgres似乎很快启动,并且没有延迟加载postgres容器问题。目前,我正在由docker-machine创建的虚拟框中运行它。
The somePostgres seems to start very quickly and There is no late loading of postgres container problem. Currently i am running this in virtual box created by docker-machine. Unable to get error as it's not persistent.
PS:添加了Dockerfile
PS: Added Dockerfile
FROM java:7
RUN apt-get update && apt-get install -y postgresql-client-9.4
ADD . ./abcd-myproj
WORKDIR /abcd-myproj
RUN ./gradlew build -x test
RUN sh db/importdata.sh
CMD ./gradlew jettyRun
推荐答案
此错误的基本含义是psql无法解析主机名,请改用ip地址。
Basically what this error means is that psql was unable to resolve the host name, try using the ip address instead.
case CHT_HOST_NAME:
ret = pg_getaddrinfo_all(ch->host, portstr, &hint,
&conn->addrlist);
if (ret || !conn->addrlist)
{
appendPQExpBuffer(&conn->errorMessage,
libpq_gettext("could not translate host name \"%s\" to address: %s\n"),
ch->host, gai_strerror(ret));
goto keep_going;
}
break;
int
pg_getaddrinfo_all(const char *hostname, const char *servname,
const struct addrinfo *hintp, struct addrinfo **result)
{
int rc;
/* not all versions of getaddrinfo() zero *result on failure */
*result = NULL;
#ifdef HAVE_UNIX_SOCKETS
if (hintp->ai_family == AF_UNIX)
return getaddrinfo_unix(servname, hintp, result);
#endif
/* NULL has special meaning to getaddrinfo(). */
rc = getaddrinfo((!hostname || hostname[0] == '\0') ? NULL : hostname,
servname, hintp, result);
return rc;
}
这篇关于psql:无法翻译主机名“ somePostgres”,地址:未知的名称或服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!